cancel
Showing results for 
Search instead for 
Did you mean: 
lonesurvivor
Nintex Newbie

Why is the javascript function for custom validation not called if drop down has no selection?

Hi everyone,

I'm investigating the following scenario:

I need a custom validation-function for a dropdown-field but on submit the function is only called if a value is selected from the dropdown. If the dropdown remains to "Please select a value...", the function is ignored.

What do I have to change so that the function is always called whether or not a value has been selected?

Greetings from Nuremberg

Ricky

Reply
9 Replies
emha
Nintex Newbie

Re: Why is the javascript function for custom validation not called if drop down has no selection?

custom validation function is invoked on submit regardless of whether you select a value or not.

have you checked you have no errors reported on developer console?

have you written validation function/script correctly?

0 Kudos
Reply
lonesurvivor
Nintex Newbie

Re: Why is the javascript function for custom validation not called if drop down has no selection?

No it's not. I wrote a simple validation function which does not gets invoked if "Please select a value..." is selected in dropdown. On every other value the console logs the message.

function checkMandatory(source, args) {  

    console.log("checkMandatory");

    args.IsValid = false;  

}

No error occurs in the console or elsewhere.

Maybe it's important to mention, that the dropdown is connected to a lookup-field.

0 Kudos
Reply
emha
Nintex Newbie

Re: Why is the javascript function for custom validation not called if drop down has no selection?

is it 'pure' dropdown control (choice) or a lookup dropdown?

0 Kudos
Reply
lonesurvivor
Nintex Newbie

Re: Why is the javascript function for custom validation not called if drop down has no selection?

Connected to a SharePoint lookup-field

0 Kudos
Reply
lonesurvivor
Nintex Newbie

Re: Why is the javascript function for custom validation not called if drop down has no selection?

I found another post here which describes the same problem: Lookup field does not validate in custom validation unless something is selected

Unfortunately there is also no solution.

I did a nasty workaround by using this JS-line to set -1 to every non-valued option in select fields:

NWF$('select:visible option[value=""]').val('-1');

But I really don't want to solve it that way. If the populating of the selects is slow, the previous code wouldn't find every option. And the using of a setTimeout-call to invoke this after a few seconds is also a no go.

0 Kudos
Reply
lonesurvivor
Nintex Newbie

Re: Why is the javascript function for custom validation not called if drop down has no selection?

I think, I found a suitable solution for the Nintex Forms Bug (I call it a bug because I can't imagine that this behavior is by design, can you confirm this Frank Field​?)

As I found out by other postings in the community and external blog posts, for current version of Forms 2.9.0.0 Nintex changed to Knockout.js. So code for fields do look like this:

<select data-bind="css: cssClass, options: lookupItems, optionsValue: 'id', optionsText: 'title', attr:{ title: helpText, id: id, disabled: !enabled(), formcontrolid: formcontrolid }, optionsAfterRender: setOptionTitle, value: selectedItem, event: { change: dropdownlistChanged }" style="width: 100%" data-use-attribute-as-value="data-nfChoiceValue" class="nf-lookup nf-ignore-getvalue nf-associated-control" title="" id="ctl00_ctl37_g_1fc7fa5f_a231_49cd_9715_b64ba17bee61_ctl00_ListForm2_formFiller_FormView_ctl78_lookup684eeaae_9943_4a27_a10c_a51f3d1905a0_Lookup" formcontrolid="eab1fb9e-7bb7-4e70-9499-ebeeab761085"><option value="" title="Please select a value..." data-nfchoicevalue="">Please select a value...</option></select>

As mentioned here, Knockout internally uses JQuery. So I can register to the "change"-event and set the value to -1 for the "Please select a value..."-option. Now the custom validation-function is always invoked no matter if a value has been selected or not. This is the code I added to register to the event:

NWF.FormFiller.Events.RegisterAfterReady(function (){

NWF$('select[id$="Lookup"]:visible').on('change', function(){

        NWF$(this).children('option[value=""]').val('-1')

    });

});

Reply
Not applicable

Re: Why is the javascript function for custom validation not called if drop down has no selection?

Euan Gamble​ will have a better answer than I will. Euan?

0 Kudos
Reply
emha
Nintex Newbie

Re: Why is the javascript function for custom validation not called if drop down has no selection?

ok, I assumed pure dropdown, since it was not fully clear from your question.

I like your code, but IMHO it's easier (more reliable?) to achieve the same by adding validation rule that checks for lookup control emptiness.

Reply
lonesurvivor
Nintex Newbie

Re: Why is the javascript function for custom validation not called if drop down has no selection?

I'm with you in the case to validate if it's important to select any option.

But what if you need to do some special validation when the selection is valid depending on values from other fields or even a remote webservice call?

Nevertheless I think, if Nintex would fix this "bug", this discussion wouldn't be necessary

0 Kudos
Reply