jqueryselectmanylistbox

This is multiselection box and required field as well. I mean 'aria-selected' is getting true after i un-select all values from selection box.


Case-1 : Select the two customers 'Customer ---> aa,bb' from selection box and save the record.(Saving successfully. ) Case-2 : Un-select two customers 'Customer ---> aa,bb' from selection box and save the record, it won't save because this selection box is required = "true". Showing required validation message and as well as selecting previous un-selected 'aa,bb' customers once again.

I want to show only 'required validation' message only if we un-select all values from selection box, i don't want to auto selection on save button. Note : This is happening only when required="true", if it isn't required then behaving fine like what i am expecting


Solution

  • you can try something like this:

    function check(required) {
    
        if (required && $("#Customer :selected").length == 0) {
            alert("selection is required!");
            return false;
        }
        return true;
    }