Skip to content

Commit

Permalink
Add access to click event on buttons
Browse files Browse the repository at this point in the history
Used built-in Vue $event special variable to pass DOM click event to button onclick functions as a third parameter.
  • Loading branch information
WilStead authored May 31, 2017
1 parent cabc1e4 commit d949421
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/formGenerator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ div.vue-form-generator(v-if='schema != null')
.field-wrap
component(:is='getFieldType(field)', :disabled='fieldDisabled(field)', :model='model', :schema='field', :formOptions='options', @model-updated='modelUpdated', @validated="onFieldValidated")
.buttons(v-if='buttonVisibility(field)')
button(v-for='btn in field.buttons', @click='buttonClickHandler(btn, field)', :class='btn.classes') {{ btn.label }}
button(v-for='btn in field.buttons', @click='buttonClickHandler(btn, field, $event)', :class='btn.classes') {{ btn.label }}
.hint(v-if='field.hint') {{ field.hint }}
.errors.help-block(v-if='fieldErrors(field).length > 0')
span(v-for='(error, index) in fieldErrors(field)', track-by='index') {{ error }}
Expand All @@ -29,7 +29,7 @@ div.vue-form-generator(v-if='schema != null')
.field-wrap
component(:is='getFieldType(field)', :disabled='fieldDisabled(field)', :model='model', :schema='field', :formOptions='options',@model-updated='modelUpdated', @validated="onFieldValidated")
.buttons(v-if='buttonVisibility(field)')
button(v-for='btn in field.buttons', @click='buttonClickHandler(btn, field)', :class='btn.classes') {{ btn.label }}
button(v-for='btn in field.buttons', @click='buttonClickHandler(btn, field, $event)', :class='btn.classes') {{ btn.label }}
.hint(v-if='field.hint') {{ field.hint }}
.errors.help-block(v-if='fieldErrors(field).length > 0')
span(v-for='(error, index) in fieldErrors(field)', track-by='index') {{ error }}
Expand Down Expand Up @@ -276,8 +276,8 @@ div.vue-form-generator(v-if='schema != null')
return field.featured;
},
buttonClickHandler(btn, field) {
return btn.onclick.call(this, this.model, field, this);
buttonClickHandler(btn, field, event) {
return btn.onclick.call(this, this.model, field, event, this);
},
// Child field executed validation
Expand Down

0 comments on commit d949421

Please sign in to comment.