validate multiselect - Move option between selects

Hi,
I read through the forums and tried for several hours now to workout a way to validate a multiselect on my form.

I have implemented the following example in a from
http://dhtmlx.com/docs/products/dhtmlxForm/samples/03_api/12_move_option.html

What I want to do is have the second multiselect validate on NotEmpty or even on a custom function but NotEmpty is only valid if all options in the second multiselect are selected and custom functions do not seem to fire.

I have tried to find a way to select all options and also to set the state of the multiselect on submit but there does not seem to be any methods public or private to allow me to do this.

its a shame that NotEmpty does not support the multiselect input type.

please advise of a way that I can validate the multiselect without having to select all the options in it.

Kind Regards
Rick

Hi

not sure I understand what the problem is

{type: “multiselect”, …, validate: “NotEmpty”}
will ‘false’ if nothing is selected in your control

{type: “multiselect”, …, validate: “NotEmpty,checkOpts”}
function checkOpts() {
console.log(arguments);
return true;
}
checkOpts will fired after NotEmpty return ‘true’ (i.e. at least one option is selected)

and you alwas can add:
dhtmlxValidation.isNotEmpty = function(){ your new code here… }

Yeah sorry i wasnt very clear.

I want to validate the arguments and have validation fire on the multiselect with nothing selected in it. It is being used as a container to hold the options that are required so I just need to see if its empty or not.

lets do this visually:

This is what I have on my form

This is what it looks like if i submit the form with the multiselect required

This is what I want it to look like when i submit the form with multiselect required

I know i can do specific validation of individual elements of a form but as far as I know there is no way to change the valid state of an individual element. so that it would firstly appear as valid (no red text) and second allow the form to submit.

If you have some work around for this it would be greatly appreciated.

Regards
Rick

I Found the solution:

It took a little while to realize you had actually given me part of the answer which was:

dhtmlxValidation.isNotEmpty = function(a){ my code here...}

The problem was that as I do not know the internal workings of the DHTMLX library. I only have access to what is Documented so i did not realize that the isNotEmpty is fired for each element of the dhtmlxForm.

To find this solution I had to deminify the dhtmlx.js file and look at your validation rules. I was then able to come up with the following solution.

dhtmlxValidation.isNotEmpty = function(a){ if(typeof a == "object"){ // the multiselect is an object in the array if(slideForm){ // this is the only form I am using the object on. var obj = slideForm.getOptions("i_blocked"); var l = obj.length; if(l > 0){ return !a == ""; // valid } else { return a.length > 0; // invalid } } } else { return (a instanceof Array ? a.length > 0 : !a == "") } }

Thanks for the help but a little more information would have saved me a lot of time. It might be a good idea to update the documentation to include isNotEmpty and how it works.