ianmartorell / meteor-accounts-ui-bootstrap-3

accounts-ui package with Bootstrap 3 and localization support
150 stars 109 forks source link

value passed to validate is always "true" #134

Closed adamwong246 closed 9 years ago

adamwong246 commented 9 years ago

I'm making a TOS checkbox, very similar to the one descried in the readme.

Accounts.ui.config
 requestPermissions: {}
 extraSignupFields: [
  {
   fieldName: 'terms'
   fieldLabel: 'I accept the terms and conditions'
   inputType: 'checkbox'
   visible: true
   saveToProfile: false
   validate: (value, errorFunction) ->
     console.log "Value is: #{value}"
     if value != 'true'
       errorFunction 'You must accept the terms and conditions.'
       false
     else
       true
  }
 ]

The problem is that no matter the state of the checkbox, the value passed to validate is always "true", regardless of whether the box is checked or not.

adamwong246 commented 9 years ago

as a workaround, you can interogate the value directly with jQuery

   validate: (value, errorFunction) ->
     if !($('#login-terms').is(':checked'))
       errorFunction 'You must accept the terms and conditions.'
       false
     else
       true
ianmartorell commented 9 years ago

I'm going to fix package-side so the jQuery validation is not needed

ianmartorell commented 9 years ago

Should work fine now, and careful with that conditional! value will be boolean, not a string.