Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meteor autoform "afFieldValueIs" with a boolean checkbox only triggers once

I have a checkbox that needs to show/hide another input box. I'm doing the following:

Schema:

isFlexibleTime:
   type: Boolean
   label: 'Is the start time flexible?'
flexibleTimeDetails:
   type: String
   label: 'Flexible time details'
   optional: true

Template:

+afQuickField(name='isFlexibleTime')

if afFieldValueIs name='isFlexibleTime' value=true
    +afQuickField(name='flexibleTimeDetails')

The helper will trigger one time and show the other field but it won't trigger again. Any help into what is wrong would be much appreciated.

like image 509
sturoid Avatar asked Oct 20 '22 14:10

sturoid


1 Answers

EDIT

Actually on further inspection it seems there is currently a bug with the checkbox event as of AutoForm 5.1.2 https://github.com/aldeed/meteor-autoform/issues/861

The issue has been open a little while, so you can use a quick workaround like:

In your template event:

'click [name=isFlexibleTime]': function() {
    Session.set('isFlexibleTime', AutoForm.getFieldValue('isFlexibleTime','ID_OF_YOUR_AUTOFORM'));
}

Template helper:

isChecked: function() {
            return Session.get('isFlexibleTime');
}

then:

{{#if isChecked}}
         {{> afQuickField name="flexibleTimeDetails"}}
{{/if}}

I'm not sure if that's your actual syntax but following the example from: http://autoform.meteor.com/fieldvalues it should look like this:

 {{> afQuickField name="isFlexibleTime"}}
 {{#if afFieldValueIs name="isFlexibleTime" value="true"}}
      {{> afQuickField name="flexibleTimeDetails"}}
 {{/if}}
like image 147
Jon Avatar answered Nov 25 '22 23:11

Jon