Skip to content

Hint function #303

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 60 additions & 56 deletions dev/full/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -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!"
})
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -319,7 +319,11 @@ module.exports = {
type: "textArea",
label: "Biography (textArea field)",
model: "bio",
hint: "Max 500 characters",
hint(model) {
if (model && model.bio) {
return model.bio.length + " of max 500 characters used!";
}
},
max: 500,
placeholder: "User's biography",
rows: 4,
Expand Down
10 changes: 9 additions & 1 deletion src/formGenerator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

Expand Down Expand Up @@ -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);
Expand Down
40 changes: 40 additions & 0 deletions test/unit/specs/VueFormGenerator.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,46 @@ describe("VueFormGenerator.vue", () => {

});

describe("check fieldHint with function", () => {
let schema = {
fields: [
{
type: "textArea",
label: "Note",
model: "note",
max: 500,
rows: 4,
hint(model) {
if (model && model.note) {
return model.note.length + " of max 500 characters used!";
}
}
}
]
};

let model = {
note: "John Doe"
};

before( () => {
createFormGenerator(schema, model);
});

it("should be applay", () => {
expect(el.querySelector(".form-group .hint").textContent).to.be.equal("8 of max 500 characters used!");
});

it("should be changed", (done) => {
model.note= "Dr. John Doe";
vm.$nextTick(() => {
expect(el.querySelector(".form-group .hint").textContent).to.be.equal("12 of max 500 characters used!");
done();
});
});

});

describe("check fieldFeatured with function", () => {
let schema = {
fields: [
Expand Down