Skip to content

Commit 4fe380e

Browse files
committed
Hint
Hint can be function.
1 parent 5099907 commit 4fe380e

File tree

2 files changed

+69
-57
lines changed

2 files changed

+69
-57
lines changed

dev/full/schema.js

+60-56
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ module.exports = {
8686
required: true,
8787
hint: "Minimum 6 characters",
8888
styleClasses: "half-width",
89-
validator: validators.string.locale({
89+
validator: validators.string.locale({
9090
fieldIsRequired: "The password is required!",
9191
textTooSmall: "Password must be at least {1} characters!"
9292
})
@@ -210,60 +210,60 @@ module.exports = {
210210
model: "",
211211
styleClasses: "alert alert-info"
212212
}, {
213-
type: "checklist",
214-
label: "CHECKLIST combobox",
215-
model: "checklistcombobox",
216-
listBox: false,
217-
values: [{
218-
name: "HTML5",
219-
value: "HTML5-123"
220-
}, {
221-
name: "Javascript",
222-
value: "Javascript-123"
223-
}, {
224-
name: "CSS3",
225-
value: "CSS3-123"
226-
}, {
227-
name: "CoffeeScript",
228-
value: "CoffeeScript-123"
229-
}, {
230-
name: "AngularJS",
231-
value: "AngularJS-123"
232-
}, {
233-
name: "ReactJS",
234-
value: "ReactJS-123"
235-
}, {
236-
name: "VueJS",
237-
value: "VueJS-123"
238-
}],
239-
}, {
240-
type: "checklist",
241-
label: "CHECKLIST listBox",
242-
model: "checklistlistbox",
243-
listBox: true,
244-
values: [{
245-
name: "HTML5",
246-
value: "HTML5-123"
247-
}, {
248-
name: "Javascript",
249-
value: "Javascript-123"
250-
}, {
251-
name: "CSS3",
252-
value: "CSS3-123"
253-
}, {
254-
name: "CoffeeScript",
255-
value: "CoffeeScript-123"
256-
}, {
257-
name: "AngularJS",
258-
value: "AngularJS-123"
259-
}, {
260-
name: "ReactJS",
261-
value: "ReactJS-123"
262-
}, {
263-
name: "VueJS",
264-
value: "VueJS-123"
265-
}],
266-
}, {
213+
type: "checklist",
214+
label: "CHECKLIST combobox",
215+
model: "checklistcombobox",
216+
listBox: false,
217+
values: [{
218+
name: "HTML5",
219+
value: "HTML5-123"
220+
}, {
221+
name: "Javascript",
222+
value: "Javascript-123"
223+
}, {
224+
name: "CSS3",
225+
value: "CSS3-123"
226+
}, {
227+
name: "CoffeeScript",
228+
value: "CoffeeScript-123"
229+
}, {
230+
name: "AngularJS",
231+
value: "AngularJS-123"
232+
}, {
233+
name: "ReactJS",
234+
value: "ReactJS-123"
235+
}, {
236+
name: "VueJS",
237+
value: "VueJS-123"
238+
}],
239+
}, {
240+
type: "checklist",
241+
label: "CHECKLIST listBox",
242+
model: "checklistlistbox",
243+
listBox: true,
244+
values: [{
245+
name: "HTML5",
246+
value: "HTML5-123"
247+
}, {
248+
name: "Javascript",
249+
value: "Javascript-123"
250+
}, {
251+
name: "CSS3",
252+
value: "CSS3-123"
253+
}, {
254+
name: "CoffeeScript",
255+
value: "CoffeeScript-123"
256+
}, {
257+
name: "AngularJS",
258+
value: "AngularJS-123"
259+
}, {
260+
name: "ReactJS",
261+
value: "ReactJS-123"
262+
}, {
263+
name: "VueJS",
264+
value: "VueJS-123"
265+
}],
266+
}, {
267267
type: "radios",
268268
label: "RADIOS",
269269
model: "radios",
@@ -319,7 +319,11 @@ module.exports = {
319319
type: "textArea",
320320
label: "Biography (textArea field)",
321321
model: "bio",
322-
hint: "Max 500 characters",
322+
hint: function (model) {
323+
if (model && model.bio) {
324+
return model.bio.length + " of max 500 characters used!";
325+
}
326+
},
323327
max: 500,
324328
placeholder: "User's biography",
325329
rows: 4,

src/formGenerator.vue

+9-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ div.vue-form-generator(v-if='schema != null')
1212
component(:is='getFieldType(field)', :disabled='fieldDisabled(field)', :model='model', :schema='field', :formOptions='options', @model-updated='modelUpdated', @validated="onFieldValidated")
1313
.buttons(v-if='buttonVisibility(field)')
1414
button(v-for='btn in field.buttons', @click='buttonClickHandler(btn, field, $event)', :class='btn.classes') {{ btn.label }}
15-
.hint(v-if='field.hint') {{ field.hint }}
15+
.hint(v-if='field.hint') {{ fieldHint(field) }}
1616
.errors.help-block(v-if='fieldErrors(field).length > 0')
1717
span(v-for='(error, index) in fieldErrors(field)', track-by='index') {{ error }}
1818

@@ -274,6 +274,14 @@ div.vue-form-generator(v-if='schema != null')
274274
275275
return field.featured;
276276
},
277+
278+
// Get current hint.
279+
fieldHint(field){
280+
if (isFunction(field.hint))
281+
return field.hint.call(this, this.model, field, this);
282+
283+
return field.hint
284+
},
277285
278286
buttonClickHandler(btn, field, event) {
279287
return btn.onclick.call(this, this.model, field, event, this);

0 commit comments

Comments
 (0)