Skip to content
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

fixes #33 - adds presence validation support for radio btns #58

Merged
merged 1 commit into from
May 24, 2015

Conversation

jamesmk
Copy link
Collaborator

@jamesmk jamesmk commented May 16, 2015

Inspired by @kirel's fix, this supports presence validation on radio buttons without a default.

@joecorcoran, @dannysperry, @saurabhbhatia let me know if you have any feedback, otherwise I'll merge it myself in a couple days.

thanks

@danieldocki
Copy link

My issue was fixed #57, good job :)

@saurabhbhatia
Copy link
Collaborator

Looks pretty good!

@danieldocki
Copy link

@jamesmk @saurabhbhatia

I was testing here and when the radio have validation inclusion, is giving as valid, when receive different values.

Example:

 validates :gender, inclusion: { in: %w(male female) }
<div class="form-group radio_buttons required user_gender">
  <label class="radio_buttons required control-label">
    <abbr title="obrigatório">*</abbr> sexo
  </label>
  <span class="radio radio-inline radio__label">
    <input class="radio_buttons required form-control" data-validate="[{&quot;kind&quot;:&quot;presence&quot;,&quot;options&quot;:{},&quot;messages&quot;:{&quot;blank&quot;:&quot;não pode ficar em branco&quot;}},{&quot;kind&quot;:&quot;inclusion&quot;,&quot;options&quot;:{&quot;in&quot;:[&quot;male&quot;,&quot;female&quot;]},&quot;messages&quot;:{&quot;inclusion&quot;:&quot;não está incluído na lista&quot;,&quot;blank&quot;:&quot;não pode ficar em branco&quot;}}]" data-klass="User" type="radio" value="malex" name="user[gender]" id="user_gender_male" style="border: 1px solid rgb(239, 72, 54);">
    <label class="collection_radio_buttons" for="user_gender_male">papai</label>
  </span>
  <span class="radio radio-inline radio__label">
    <input class="radio_buttons required form-control" data-validate="[{&quot;kind&quot;:&quot;presence&quot;,&quot;options&quot;:{},&quot;messages&quot;:{&quot;blank&quot;:&quot;não pode ficar em branco&quot;}},{&quot;kind&quot;:&quot;inclusion&quot;,&quot;options&quot;:{&quot;in&quot;:[&quot;male&quot;,&quot;female&quot;]},&quot;messages&quot;:{&quot;inclusion&quot;:&quot;não está incluído na lista&quot;,&quot;blank&quot;:&quot;não pode ficar em branco&quot;}}]" data-klass="User" type="radio" value="female" name="user[gender]" id="user_gender_female" style="">
    <label class="collection_radio_buttons" for="user_gender_female">mamãe</label>
  </span>
</div>

@jamesmk
Copy link
Collaborator Author

jamesmk commented May 16, 2015

@danieldocki Yeah, radio btn will have all sorts of weird edge cases like this. We'd have to add a radio specific conditional to each validator. That's not a priority though, because most of the use cases don't make sense. Inclusion, for example, can be defined by the radio btn values. Adding it as a validation seems redundant.

@danieldocki
Copy link

@jamesmk make sense

jamesmk added a commit that referenced this pull request May 24, 2015
fixes #33 - adds presence validation support for radio btns
@jamesmk jamesmk merged commit 834cf5c into master May 24, 2015
@jamesmk jamesmk deleted the radio-presence-fix branch May 25, 2015 20:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants