Skip to content

Add support for schema.legend & field.id prefixes #206

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

Closed

Conversation

dflock
Copy link
Collaborator

@dflock dflock commented May 25, 2017

  1. 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"
    },
...
  1. 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. So if you have this:
schema: {
  legend: "Contact Details",
  fields: [
    {
      type: "input",
      inputType: "text",
      label: "Name",
      model: "name"
    },
    {
      type: "input",
      inputType: "email",
      label: "Email",
      model: "email",
      id: "user_email"
    }
  ]
},


formOptions: {
  fieldIdPrefix: 'frm1_'
}

you'll get this:

<fieldset class="vue-form-generator">
  <legend>Contact Details</legend>
  <div class="form-group field-input">
    <label for="frm1_name">Name</label>
    <div class="field-wrap">
      <div class="wrapper">
        <input id="frm1_name" type="text" class="form-control">
      </div>
    </div>
  </div>
  <div class="form-group field-input">
    <label for="frm1_email">Email</label>
    <div class="field-wrap">
      <div class="wrapper">
        <input id="frm1_email" type="email" class="form-control">
      </div>
    </div>
  </div>
</fieldset>

So the idPrefix is (intentionally) applied to both auto-generated and manually set field ids.

I added a dev/multipleforms thing to demo this - which should probably be called multiplefieldsets or legends or something.

* 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.
@icebob
Copy link
Member

icebob commented May 25, 2017

I will check it.

@jmverges
Copy link
Contributor

👍

@jmverges
Copy link
Contributor

One thing, regarding this,

should we then use several one for each legend?

I would check if in schema exists a property called groups which is an array with objects like {legend:'Something',fields:[]} and if that property doesn't exist then go fields.

Definitely, this kind of feature is needed but having more than one tag has no sense for me

Cheers,

@@ -1,6 +1,7 @@
<template lang="pug">
div
fieldset.vue-form-generator(v-if='schema != null', :is='tag')
legend(v-if='schema.legend') {{ schema.legend }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add a bit more of logic in here to not need more than one tag

@@ -122,6 +123,13 @@ div
}
},

beforeMount() {
// Add idPrefix to fields if fieldIdPrefix is set
for (let field of this.schema.fields) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

@icebob
Copy link
Member

icebob commented May 25, 2017

@jmverges Yes, it would be good, because the grouping is an old todo 👍

@jmverges
Copy link
Contributor

@dflock are you gonna take care or would you prefer if I fork your branch and do the stuff?

@icebob I have a question, it is possible to update the schema and rebuild it once is created?

@icebob
Copy link
Member

icebob commented May 25, 2017

If you change the schema the Vue will be rebuild the DOM. (I think) I didn't try it. I use to change the complete schema.

@jmverges
Copy link
Contributor

I think is not working for me

@jmverges
Copy link
Contributor

jmverges commented May 25, 2017

@dflock @icebob I have a groups versions locally working. Should I create a new PR?

Edit: tests are failing

@icebob
Copy link
Member

icebob commented May 25, 2017

Wow, you are very fast :) Yes, please open a new PR

@icebob
Copy link
Member

icebob commented May 25, 2017

Closed by #209

@icebob icebob closed this May 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants