-
Notifications
You must be signed in to change notification settings - Fork 30
Support multi-value fields like array_name[]
or many checkboxes with the same name
#18
Comments
Hi Ismail, I see your point. But it's a bit tricky about names with |
@rguliev I have the same issue with names with |
Hi @BassemN , |
@rguliev Please check the following example https://codepen.io/anon/pen/dwGEyW?editors=1000 |
Yes, I can see this being a problem too, with many CMS using weird class names with brackets etc... |
@BassemN, Thanks! Additional thanks for <input type="text" name="my_favorite_books[]">
<input type="text" name="my_favorite_books[]">
<input type="text" name="my_favorite_books[]">
<button id="add_book_btn">Add a book</button> And according to the issue title and suggested regex change, I think that the initial question is about such a case. But it is ambigous to get values and check conditions for such fields. That is why I refused to add it without any further details. |
@rguliev Welcome :) |
Is there any ETA on this as it is very critical for my project as my checkboxes & selects are using names[ ] and it is not ideal to use ID's for this project, thank you. |
My situation is similar to this you mentioned above :
|
@CodeCurosity As I said, for such cases the plugin would not work well. The problem is that it is ambiguous which value you want to check. It would help if you provide a more detailed example with the context. |
Here https://codepen.io/digtalmind/pen/ZVOYYr For checkboxes & select we have to use [ ] next to the name so it can be submitted as an array. |
What does the condition Well, here are options you have:
As for 'my_favorite_books[]' it is not considered for implementation because it is a very unclear case. I think it's easier to add some JS (as you will need it anyway if you use muti-fields) to add numbers to IDs or names. |
|
Yeah, sorry did not notice values. |
For it to work without brackets we also have to remove [ ] from names which we can't do, its just very odd that we have to tell client to use names for certain fields and ids for other fields. |
You can use both names and IDs; or names for all fields and add IDs only for those used in conditions. Or you can name them without brackets like |
Thanks to IsmailM this solution worked perfectly : https://codepen.io/ismailm___/pen/QzEbyZ?editors=1010 |
|
array_name[]
array_name[]
or many checkboxes with the same name
Closed related issue #28 . Let's keep our discussions in one place. Our summary so far: Not working cases
<label><input type="checkbox" name="options" value="1">Option1</label>
<label><input type="checkbox" name="options" value="2">Option2</label>
<label><input type="checkbox" name="options" value="3">Option3</label>
<button id="add_book_btn" class="conditional" data-condition="options == 2">
<label>Favorite book name</label><input type="text" name="my_favorite_books[]">
<label>Favorite book name</label><input type="text" name="my_favorite_books[]">
<label>Favorite book name</label><label><input type="text" name="my_favorite_books[]">
<button id="add_book_btn" class="conditional" data-condition="my_favorite_books[] == 3">
Suggested solution
About ETA |
So Multi Value Checkboxes don't even work with names, id's & names with [ ] , i have tried below doesn't work either, this is very critical we can wait for name [ ] but it should work with ID's, look at the example below :
|
@CodeCurosity |
Thanks, @BassemN. |
Yeah i just recalled, thanks i guess for now i will give unique id to each of my checkboxes. |
Yes i think giving unique id's to each of my input is the ideal way to go at the moment as my field names are coming from labels and i only wanted to make it easier for my clients to see the names while they are creating the logic, now i will just generate the unique id next to the input so they can use ID's, thanks guys 👍 |
Welcome:) |
Multi Radio buttons also don't seem to work although i am using id's for condition and each radio button has different id but same name. https://codepen.io/digtalmind/pen/ZVOYYr/ It shows the field but it doesn't hide when other radio button is clicked. Checkboxes on the other hand with different id's work just fine even though they have same name and even have [ ] at the end. |
You are confusing things. Radio buttons are not a multi-value inputs. Multi-value means that an input has many values and when you send it to the server side it will appear something like an array. On the other hand, using the same name for many inputs in case of a radio button is an expected syntax. Why? Because radio button takes only one value even though you have many inputs with the same name. Because it is the way radio buttons are designed and work. So you can just ask for a value of a radio button. In case of your example just try |
I never mentioned anywhere that radio buttons are multi value, i just mentioned i have multi radio buttons, previously we had issues with multi check boxes with same name or [ ] so i replanned everything and decided to stick to ID's now that i have given unique id to every input radio buttons doesn't seem to work with ID's? the sole purpose of using multi radio buttons is so clients can select one value from multiple options, i still can't get my head wrapped around that why it doesn't work with ID even though i gave the value? I tried data-condition="#id" or data-condition="#id == 2" none of these options work multiple radio buttons. I think this is very odd that it shows the field but then it doesn't hide the field when other options are selected even though you can see the selected radio button is no longer selected, it seems to me like a bug. Please understand that we can either work with names or with ID, we need to give our clients the selector to select fields so it can either output ID or Name. |
I see your point. But getting a value of a radio button by id is odd even more. I understand that you kinda have to because you want multi-value radio buttons. But the problem is that javascript does not trigger a change event for one of radio buttons input. Get better understanding try following: <label><input id="mybox0" type="radio" name="my_favorite_books" value="0">Option0</label>
<label><input id="mybox1" type="radio" name="my_favorite_books" value="1">Option1</label>
<label><input id="mybox2" type="radio" name="my_favorite_books" value="2">Option2</label>
<script>
$('#mybox1').change(function(){
console.log('Change is triggered');
})
</script> So, a workaround you can use is to trigger change events manually: $('#mybox, #mybox2').change(function(){
$('#mybox1').trigger("change");
});
$(document).ready(function() {
$('.conditional').conditionize();
}); And change data-condition to just the id, i.e. |
I can trigger change event manually but unfortunately fields are generated on the fly and i can only get unique id of each input, i can't define other radio buttons id's in a function. Can i manually trigger change event on each input by specifying just that input unique ID? |
I think you have to write some additional javascript handling event triggering. Or maybe it will be simpler for you to write your own conditionize.js working just for your special project. But it is out of scope here. I would recommend asking at Stack Overflow with comprehend description, so more people could help you. |
@CodeCurosity Just chiming in to say @rguliev is correct and the use case you're describing seems very specific to what you're trying to achieve. You may wish to try writing your own event handling or forking this plugin to make changes specific to your needs. |
Thanks guys yes i will do that 👍 |
Really looking forward to get this by the end of january 👍 |
Hey guys, end of january, anything on this issue, its really bugging my clients to not been able to use radio button and checkboxes at all. |
Hi @CodeCurosity, |
Hi,
Thanks. |
The problem is that now P.S. For further discussions, please, use issues in the new repo, since it’s irrelevant here. |
Hey!
Why I did not keep it in this repo:
The new version is a fork from this repo because I wanted to give credits to other contributed developers. First, I thought about transferring the repo but I was not able to contact the owner anyway. So now I stop maintenance of |
Exciting! Thank you for taking over maintenance/improving this project, @rguliev! |
Thank you for the inspiration and the opportunity to contribute! |
Hey,
The original
conditionize.js
works with names with[]
but it would be nice to upgrade toconditionize.flexible.js
...The original version cleaned the parameter to take this into account
conditionize.js/conditionize.jquery.js
Line 49 in 4120b6d
The new version uses
\w
in a regex which doesn't match[\w+]
conditionize.js/conditionize.flexible.jquery.js
Line 31 in 4120b6d
Perhaps changing the regex to
(#?[\w\[\]]+)
will fix this issue?The text was updated successfully, but these errors were encountered: