0
I have a page where there are some selects (representing the functions of users, in which they can be: Leader, Participant or For Knowledge).
There are some business rules:
1- If the user is selected as LEADER, he can no longer have any other function, should only have a (Leader);
2 - Shall not contain more than one leader. For example, I have a list with 3 users and select one of them as LEADER, in the other selects the LEADER option should be disabled, because only a single user is allowed to be the Leader;
I already managed to do this validation in the existing selects on the page, but has the option to add more users in the list. And that’s where my validation doesn’t work, because if I’m already with a user LEADER (selected) and want to add another user in my list, the select of this new user (which is added dynamically via JS) should already come with the option LEADER disabled, because on my list (before adding this new user) there was already a Leader user.
How to check the selected options, so that the validation works also on new users that are added dynamically?
Hello, Could show how you are doing?
– Bruno Spy
André, how are you adding this new
select
? Are you cloning or adding a string html?– Sergio
It’s by string, @Sergio
– André Albson
You can add to the question the code that inserts that new select?
– Sergio
I edited the question by adding the image of how I’m doing to add the new select, @Sergio
– André Albson
I believe I would only need to create a method that would check the selected options, and if Leader is already selected in some select, the new select would be added and automatically its Leader option would be disabled... But I don’t know how to do it.
– André Albson