I have a form to save contacts and each contact can have multiple contact info for instance, a primary and then mailing, other etc. I want to set up a server side validation so that if more than one contact info entry is marked as ‘Primary’ then submitting the form fails.
Is this possible using the ‘unique’ validator in Wappler and if so how do you use it per id? If not possible, can I write my own validator and is there documentation on how to do so?
Thanks in advance.
Couldn't see a way to do it and on a time crunch so I wrote some quick jQuery to deal with it on the client side at least until I figure out how to do it on the server side. I also need to force them to make one of them primary.
$('body').on('change','.contact-info-type',function(){
$(this).addClass('changed');
if ($(this).val() == 'Primary'){var this_is_primary = true;var has_primary = true;}else{var this_is_primary = false;var has_primary = false;}
$('#modal_contacts').find('.contact-info-type:not(.changed)').each(function(){
var the_text = $(this).find(":selected").text();
if (!this_is_primary && the_text == 'Primary'){var has_primary = true;}
if (this_is_primary && the_text == 'Primary'){$(this).val('Other').trigger('change');}
});//each
$(this).removeClass('changed');
if (!has_primary){alert('Please set one contact info as Primary');}
});