From 4fe380ec161b98b614cf4d6d71ab2f067dfff513 Mon Sep 17 00:00:00 2001 From: hansi90 Date: Wed, 4 Oct 2017 10:57:56 +0200 Subject: [PATCH] Hint Hint can be function. --- dev/full/schema.js | 116 ++++++++++++++++++++++-------------------- src/formGenerator.vue | 10 +++- 2 files changed, 69 insertions(+), 57 deletions(-) diff --git a/dev/full/schema.js b/dev/full/schema.js index 52d5aa83..ae849bd9 100644 --- a/dev/full/schema.js +++ b/dev/full/schema.js @@ -86,7 +86,7 @@ module.exports = { required: true, hint: "Minimum 6 characters", styleClasses: "half-width", - validator: validators.string.locale({ + validator: validators.string.locale({ fieldIsRequired: "The password is required!", textTooSmall: "Password must be at least {1} characters!" }) @@ -210,60 +210,60 @@ module.exports = { model: "", styleClasses: "alert alert-info" }, { - type: "checklist", - label: "CHECKLIST combobox", - model: "checklistcombobox", - listBox: false, - values: [{ - name: "HTML5", - value: "HTML5-123" - }, { - name: "Javascript", - value: "Javascript-123" - }, { - name: "CSS3", - value: "CSS3-123" - }, { - name: "CoffeeScript", - value: "CoffeeScript-123" - }, { - name: "AngularJS", - value: "AngularJS-123" - }, { - name: "ReactJS", - value: "ReactJS-123" - }, { - name: "VueJS", - value: "VueJS-123" - }], - }, { - type: "checklist", - label: "CHECKLIST listBox", - model: "checklistlistbox", - listBox: true, - values: [{ - name: "HTML5", - value: "HTML5-123" - }, { - name: "Javascript", - value: "Javascript-123" - }, { - name: "CSS3", - value: "CSS3-123" - }, { - name: "CoffeeScript", - value: "CoffeeScript-123" - }, { - name: "AngularJS", - value: "AngularJS-123" - }, { - name: "ReactJS", - value: "ReactJS-123" - }, { - name: "VueJS", - value: "VueJS-123" - }], - }, { + type: "checklist", + label: "CHECKLIST combobox", + model: "checklistcombobox", + listBox: false, + values: [{ + name: "HTML5", + value: "HTML5-123" + }, { + name: "Javascript", + value: "Javascript-123" + }, { + name: "CSS3", + value: "CSS3-123" + }, { + name: "CoffeeScript", + value: "CoffeeScript-123" + }, { + name: "AngularJS", + value: "AngularJS-123" + }, { + name: "ReactJS", + value: "ReactJS-123" + }, { + name: "VueJS", + value: "VueJS-123" + }], + }, { + type: "checklist", + label: "CHECKLIST listBox", + model: "checklistlistbox", + listBox: true, + values: [{ + name: "HTML5", + value: "HTML5-123" + }, { + name: "Javascript", + value: "Javascript-123" + }, { + name: "CSS3", + value: "CSS3-123" + }, { + name: "CoffeeScript", + value: "CoffeeScript-123" + }, { + name: "AngularJS", + value: "AngularJS-123" + }, { + name: "ReactJS", + value: "ReactJS-123" + }, { + name: "VueJS", + value: "VueJS-123" + }], + }, { type: "radios", label: "RADIOS", model: "radios", @@ -319,7 +319,11 @@ module.exports = { type: "textArea", label: "Biography (textArea field)", model: "bio", - hint: "Max 500 characters", + hint: function (model) { + if (model && model.bio) { + return model.bio.length + " of max 500 characters used!"; + } + }, max: 500, placeholder: "User's biography", rows: 4, diff --git a/src/formGenerator.vue b/src/formGenerator.vue index 47ae7b0b..833a0580 100644 --- a/src/formGenerator.vue +++ b/src/formGenerator.vue @@ -12,7 +12,7 @@ div.vue-form-generator(v-if='schema != null') 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, $event)', :class='btn.classes') {{ btn.label }} - .hint(v-if='field.hint') {{ field.hint }} + .hint(v-if='field.hint') {{ fieldHint(field) }} .errors.help-block(v-if='fieldErrors(field).length > 0') span(v-for='(error, index) in fieldErrors(field)', track-by='index') {{ error }} @@ -274,6 +274,14 @@ div.vue-form-generator(v-if='schema != null') return field.featured; }, + + // Get current hint. + fieldHint(field){ + if (isFunction(field.hint)) + return field.hint.call(this, this.model, field, this); + + return field.hint + }, buttonClickHandler(btn, field, event) { return btn.onclick.call(this, this.model, field, event, this);