New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix name and id for checkbox/radio #251
Conversation
cefd836
to
b39966f
Compare
Thanks for the PR! It has been a while since I've touched this code, so I will need your help to be able to fully review and merge this. Could you explain in more detail the bug you are fixing, and what changes were necessary? Also, I'll need you to fix the test failure and add a CHANGELOG entry before this can be merged. Thanks! |
In current version of bootstrap_form_tag, name, id and for properties are not properly generated just because there is no object name to refer to. The second patch allow to be able to pass "for" parameter to the label in a control group. In the current version, there is no way to specify a specific I'm not fluent in english so it's hard to turn all this in proper english. I've fixed the tests |
Thanks for the explanation! I'll review this week. In the meantime, can you add an entry to the CHANGELOG file as part of this PR? |
I've tried this PR and I'm still getting |
Sorry to hear that Dan. I use my patch in production, and it work properly so I'm not sure why it isn't working for you. There is also a test that validate the name format. Maybe you could try to debug your code or provide an example of what you do exactly ? |
If you need, here is a live example:
it converts to
|
@veilleperso This is what I did:
But got this output:
|
I see: i just fixed the generation of name and id for checkbox/radio (as stated in the tile), and that extend to any input field as they work the same. But I didn't take care of select tag which use a different code. I will look into it. |
Also, using the documented way for radio buttons, makes the html come out like this:
|
I think that for radio_button the proper way to do it is not use :value => "foo" , but to pass the value as you would with bootstrap_form ... So your bug seems to be much more related to the way you build your code, as you seem to have copied the exemple of a text_field to a radio_button, but they are not built the same way ... |
@veilleperso Select works now as well. Thank you |
Same problem with hidden fields though |
hidden_field are not processed by rails-bootstrap-form, I can't find any specific code related to hidden field, so I guess the problem is that hidden field are delegated to rails without specific processing by rails-bootstrap-form like for all other fields ... But feel free to address this specific issue if you need it for your own use. |
@veilleperso @dan-klasson Thanks for all your help on this! Would you say this is ready for merge? Also, if we are going to leave |
@mattbrictson no need for a PR, i had a quick look this morning and i guess this last patch should fix the hidden_field tag... I also added a test for it. I guess now everything is ready to merge. |
When using bootstrap_form_tag, "name" and "for" properties for check_box and radio_button are not properly generated, because there is no objet to refer to This patch fix that to restore proper naming.
When generating a label in a form_group, we preserve the +for+ information if this information exist
* +for+ parameter must be properly according to specified id, when an id is provided * +for+ parameter must be used when provided in label hash params
* Follow the rails naming rules for id and name when using bootstrap_form_tag and select tag * Allow the use of label: "My String" in form_group, to mimic what is allowed in other bootstrap tags (ie label can be either a string or a hash)
Use the proper rails naming convention for id/name when using bootstrap_form_tag
Still having the problem with the hidden field. But can leave for later. |
Sorry Dan, but i don't see any problem on hidden field
gives me
|
@veilleperso hidden fields with |
Sorry to hear that @dan-klasson but it's outside of the scope of this patch: I only patched a few things for bootstrap_form_for only, mainly for my own needs at first... BTW "not working" is a pretty vague concept, so it's hard to help you ;-) It would probably help if instead you show us some code that "don't work" ? |
@veilleperso No worries. Not sure how to use hidden field with I'll review your code changes and submit my own PR. |
@dan-klasson Here is an exemple of use from code in production, where "Invoice" is an activerecord object with a field customer_id
The resulting html is:
As you can see the hidden field is properly generated, using the id I manually specified, and properly building the name field So I guess that the problem is much more in the way you write your code, than in the gem or my patch. Again, my patch didn't concern form_for, only bootstrap_form_for. |
@veilleperso @dan-klasson I lost track of the discussion here. Have all the issues been resolved and is this PR good to merge? Let me know, thanks! |
If provided, use option `id` to specify `for` attribute on label for (text, email...) fields, checkbox, radio and select. Solves bootstrap-ruby#342 issue and supercede bootstrap-ruby#221 and bootstrap-ruby#343 pull requests. Partially solves bootstrap-ruby#251 (only the part regarding the id).
Thank you for your interest in improving If you still believe this PR is needed, please re-open it and update it to be mergeable with the current master. Our apologies for not responding sooner. |
* Use option[:id] for label's *for* attribute If provided, use option `id` to specify `for` attribute on label for (text, email...) fields, checkbox, radio and select. Solves #342 issue and supercede #221 and #343 pull requests. Partially solves #251 (only the part regarding the id). * Move require mocha/minitest as needed by newer version. * Fix version of sqlite3 < 1.4 so tests will work.
When using bootstrap_form_tag, "name", "id" and "for" properties for check_box and radio_button are not properly generated, because there is no objet_name to refer to.
This patch fix that to restore proper naming of checkboxes and radio buttons.