How to activate the framework required fields feature?

In Servoy Navigation Configurator → “Program”-> “Fields” → on the desired dataprovider there is the checkbox “required” activated, but it seems that it does not work, if the associated form is saved and the field is not filled. What is the correct way to use the feature?

As far as I know that is taken care of in svy_nav_checkRequiredFields, at least that is where it is taken care of in my case.

Thanks for the hint. How can I get: {Object} _progObj the object of the current program?

svy_nav_checkRequiredFields(_progObj:Object, _form:String)
Check if all the required fields are entered, otherwise put warning in the validation_msg 
Parameters:
{Object} _progObj the object of the current program
{String} _form the name of the form

Use something like this:

	var toolbarForm = getToolbarFormName()
	var program = forms[toolbarForm].vProgram

jdbruijn:
Use something like this:

	var toolbarForm = getToolbarFormName()
var program = forms[toolbarForm].vProgram

What is vProgram?

vProgram is a property on the toolbar form, the Framework sets it with the program_name.

jdbruijn:
vProgram is a property on the toolbar form, the Framework sets it with the program_name.

If I try the following on the form which should be checked:

function dc_save(_event, _triggerForm) {
	_super.dc_save(_event, _triggerForm);
	var toolbarForm = getToolbarFormName();
	var program = forms[toolbarForm].vProgram;
	globals.svy_nav_checkRequiredFields(program,'MyForm');
	return
}

I get the error message:

TypeError: Cannot call method "getFields" of (H:\servoy7_workspace\svy_nav_navigation\globals.js#2425)

What is wrong?

why do you first call the _super function?
anyways if the _super.dc_save is the function in svy_nav_base than you don’t need to call this manually, because one of the first steps of dc_save is to call dc_save_validate and in there the required fields are checked using svy_nav_checkRequiredFields.
I suggest you step through the dc_save function and have a look at what happens there.

jdbruijn:
why do you first call the _super function?
anyways if the _super.dc_save is the function in svy_nav_base than you don’t need to call this manually, because one of the first steps of dc_save is to call dc_save_validate and in there the required fields are checked using svy_nav_checkRequiredFields.
I suggest you step through the dc_save function and have a look at what happens there.

So I only have to mark the required fields in Servoy Navigation Configurator for a form and then the fields are marked with ** and I get a message at save, that the fields needs to be entered? If this is the case and does not work, the _super.dc_save has been changed?

Yes that is how it is supposed to work.
Have you tried stepping through svy_nav_base.dc_save ? Do you get into dc_save_validate and from there in svy_nav_checkRequiredFields?

The problem was that there was no label for the required field. Further the label property name was not set to the element name defined for the field in Servoy Navigation Configurator → “Program”-> “Fields” and the property labelFor was not assigned to the desired field.

But now the next problem occurs.:

[attachment=0]2013-06-19 14_53_21-Entschuldigen Sie.png[/attachment]

Why is the name of the required field not shown?

i’ve modified the standard code for this, but if I remember correctly it looks for the correct label (using the labelFor property of the field) and gets the text property of that label to show in the dialog.
What do you get when you inspect the label element in svy_nav_checkRequiredFields?

jdbruijn:
i’ve modified the standard code for this, but if I remember correctly it looks for the correct label (using the labelFor property of the field) and gets the text property of that label to show in the dialog.
What do you get when you inspect the label element in svy_nav_checkRequiredFields?

application.output("label element: "+_label); at the end of svy_nav_checkRequiredFields shows:

label element: undefined
label element: fld_beleginfo

There seems to be a field that has no labelFor set.

jdbruijn:
There seems to be a field that has no labelFor set.

On that form are a lot of labels that doesn’t have the property labelFor set, but I have only one field that is set to required. How can I find what causes the output of: “label element: undefined”?

set a breakpoint to trigger when _label == null
or add logging with the loop counter and the field name.

The problem occurs in the function svy_nav_checkRequiredFields.:

globals.nav.validation_msg += i18n.getI18NMessage("svy.fr.dlg.is_required", [utils.stringReplace(_formObj.elements[_label].text, '* ', '')]) + "
";

It’s a bug, I think.

Are you sure the error is in that function and not in svy_nav_checkRequiredFields?
That is where the fields are retrieved:

	var _fields = _jsForm.getFields()

This loop is where the validation is performed.

	for (var i = 0; i < _fields.length; i++) {
		_fieldName = _fields[i].name
		_fieldDataprovider = _fields[i].dataProviderID
		if (_progObj['required_fields'][_fieldDataprovider] && _progObj['required_fields'][_fieldDataprovider].on_form && _formObj.elements[_fieldName].getLabelForElementNames)//this is a required field
		{
			_label = _formObj.elements[_fieldName].getLabelForElementNames()[0]
			if (_label && !_formObj[_fieldDataprovider]) { //field is not entered

				globals.nav.validation_msg += i18n.getI18NMessage("svy.fr.dlg.is_required", [utils.stringReplace(_formObj.elements[_label].text, '* ', '')]) + "
";
				_return = -1
			}
		}
	}

This will result in an error when you have a required field that has no name, but when you have no label defined as the labelFor than you will not get an error.
I suggest you have a good look at what happens here when you loop through all your fields.

Have you tried this with a smaller form? Or temporarily remove most of your fields from your form, just leave the required field(s) and see what happens.
Without knowing your forms and settings, that is about all I can tell you.

I usually make sure that all my components have a name, so you can always be sure that you can reference the field/label through code.

I replaced in the i18n key svy.fr.dlg.is_required:

, is required and was not filled.
, wird benötigt und wurde nicht ausgefüllt

with:

{0}, is required and was not filled.
{0}, wird benötigt und wurde nicht ausgefüllt

Now, I get this:

[attachment=0]2013-06-20 11_44_31-Entschuldigen Sie.png[/attachment]

The message:

label element: undefined

occurs, because of:

			if (_formTab && forms[_formTab]) {
				_return_call = globals.svy_nav_checkRequiredFields(_progObj, _formTab)

and then:

var _label
``` never filled, because on the tabpanel / tab was no label.

![2013-06-20 11_44_31-Entschuldigen Sie.png|350x148](upload://83ItlW1IeE2dSuVokMMGR1a8BlG.png)

I am looking in the code and the i18n key of svy.fr.dlg.is_required has the values:

The field {0} is required and was not filled
Das Feld {0} darf nicht leer sein