Hi,
I have a form that needs to be validated.
I need to be sure that in smart-select multiple options, at least one is selected (but can be more than one).
I’d prefer to make the validation once the smart-select is closed.
1- Which event is triggered when the smart select is closed?
2- How can I change the values in the form (due to validation) and find them in the smart select when i reopen (for example, user selects nothing and app selects automatically all the options)
Similar question for point 2 is for picker: it seems a change in input does not reflects automatically in values of the picker…
$$('#form_entry_item').on('change', function() {
console.log('Form entry item was changed was changed!');
//detect if picker is closed after a selection is made for additional actions:
$$('.picker-modal').on('close', function() {
console.log('Picker closed after selecting an item!');
//additional actions here
});
});
Comment on my solution suggested above: This works but the issue with it is that a new event handler is created upon every selection made in the smart-select, even prior to hitting “Done” and closing the smart select, so that when the smart select is finally closed the inner .on(‘close’) event will trigger once for every selection that was made instead of just the last selection as desired.
I suggest the solution below which keeps the two events separate and set a flag variable within the .on(‘change’) event that is tested within the .on(‘close’) event such that the additional actions are conditioned upon the .on(‘change’) event happening.
Is there a better way to approach this?
var itemSelected = false;
$$('#form_entry_item').on('change', function() {
console.log('Form entry item was changed was changed!');
var itemSelected = true;
});
//detect if picker is closed after a selection is made for additional actions:
$$('.picker-modal').on('close', function() {
if (itemSelected) {
console.log('Picker closed after selecting an item!');
//additional actions here
}
});
>