-
Notifications
You must be signed in to change notification settings - Fork 533
Groups, Form id and prefix #208
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
Conversation
* Add support for an optional legend for each schema/fieldset. Expects the schema to look something like this: ``` schema: { legend: "Contact Details", fields: [ { type: "input", inputType: "text", label: "Name", model: "name" }, ... ``` * Add support for field id prefixes, at the form level. So you can add a `fieldIdPrefix: 'prefix_here_'` to your `formOptions` and this will be prepended to _all_ field id's.
* Add support for schema.groups, schema.groups legend & field id prefixes * Add support for grouping fields. You still can to put fields as always in combination with groups. * Add support for an optional legend for each group/fieldset. Expects the schema to look something like this: ``` section1: { groups:[{ legend: "Contact Details", fields: [ { type: "input", inputType: "text", label: "Name", model: "name" }, { type: "input", inputType: "email", label: "Email", model: "email" } ] },{ legend: "Other Details", fields: [ { type: "input", inputType: "text", label: "More", model: "more" }, { type: "input", inputType: "text", label: "Things", model: "things" } ] }] }, ``` * Add support for field id prefixes, at the form level. So you can add a `fieldIdPrefix: 'prefix_here_'` to your `formOptions` and this will be prepended to _all_ field id's. Based on phemisystems@a6165c8 @dflock @phemisystems
Tests are falling, @icebob could you take a look? |
I find an issue here but I don't know how to solve. When you assign to schema a new schema while having groups, a weird behaviour happens: Groups are duplicated without fields, and fields are duplicated in previous groups @icebob |
What you want to output is something like this: <form>
<fieldset>
<legend>blah</legend>
<!-- field here -->
<!-- field here -->
<!-- field here -->
</fieldset>
<fieldset>
...
</fieldset>
...
</form> So, each group outputs a Currently vfg outputs a single fieldset, so you can get this output by just having one schema per "group", adding a legend to each schema, and calling vfg multiple times, once per "group". This is what I did, because it seemed simpler. If you're going to do this with one call to vfg, then you need something like your PR, but the output should still look like the above. I can't actually try this out until later, but just eyeballing the diff, it looks like you're outputting a |
No, the fieldset generation is correct after pushing a couple of bugfixes. However I think :schema.sync='field' maybe is the one causing some problem. I don't know, never used sync in my daily work. But I think the solution is so close, probably @icebob will know what to do. |
I'm checking... |
I checked and it seems it's working. I only fixed an undefined error here |
could you try to update the hole schema to see if the binding works as expected? |
I don't know what you mean. You can also try it if you checkout pr208 branch |
You're correct, the output looks OK, sorry about that. It does break the field prefixes, though. You need to change the beforeMount() {
// Add idPrefix to fields if fieldIdPrefix is set
if ("groups" in this.schema) {
for (let group of this.schema.groups) {
for (let field of group.fields) {
field.idPrefix = this.options.fieldIdPrefix || "";
}
}
} else if ("fields" in this.schema) {
for (let field of this.schema.fields) {
field.idPrefix = this.options.fieldIdPrefix || "";
}
}
}, It's a shame that both the template - and now the Thoughts? |
Actually that doesn't work properly where you have a schema that has beforeMount() {
// Add idPrefix to fields if fieldIdPrefix is set
if ("groups" in this.schema) {
for (let group of this.schema.groups) {
for (let field of group.fields) {
field.idPrefix = this.options.fieldIdPrefix || "";
}
}
}
if ("fields" in this.schema) {
for (let field of this.schema.fields) {
field.idPrefix = this.options.fieldIdPrefix || "";
}
}
}, |
@dflock The code is good just duplicated. I'm searching a lodash func which merge fields from |
Also, the <div class="vue-form-generator">
<div>
<legend>Contact Details</legend>
<div class="form-group field-input">
...
</div>
</div>
<div>
<legend>Other Details</legend>
...
</div>
</div> So, a The tag parameter was originally introduced because vfg always wrapped it's output in a With these changes, it now always wraps it's output in a In fact, I would probably change |
I think we leave :tag to |
Follow #206