Skip to content

Grouping fields #209

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 11 commits into from
May 31, 2017
Merged

Grouping fields #209

merged 11 commits into from
May 31, 2017

Conversation

icebob
Copy link
Member

@icebob icebob commented May 25, 2017

This PR add two new features to vfg by @dflock & @jmverges.

  1. add ID prefix for fields
  2. support to grouping fields of schema
    Syntax:
schema: {
    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: "others.more"
            },
            {
                type: "input",
                inputType: "text",
                label: "Things",
                model: "others.things"
            }
        ]
    }],
    fields: [
        {
            type: "input",
            inputType: "text",
            label: "Single field (without group)",
            model: "single"
        }
    ]
}

Dev example: http://localhost:8080/grouping/

Duncan Lock and others added 7 commits May 24, 2017 19:39
* 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
add options prop to abstractField
remove beforeMount
@jmverges
Copy link
Contributor

jmverges commented May 25, 2017

@icebob what I try to explain before is:

       mounted(){
            let $this = this;
            this.$watch('model', function () {
                let prop = {};
                clearTimeout($this.timer);
                $this.timer = setTimeout(function () {
                    $this.build();
                    $this.schema = {groups:$this.getSheets()};
                }, 1000);
            }, {deep: true});
            this.build();
            this.schema =  {groups:$this.getSheets()};
        },

I'm recreating the schema each time the model changes as the schema has linked between them. Each time I update schema, a weird behaviour happen. First: https://cloud.githubusercontent.com/assets/2902073/26468867/43976b56-4198-11e7-8701-2a5928441104.png Then I select a VehicleType https://cloud.githubusercontent.com/assets/2902073/26468961/a941a4b2-4198-11e7-8116-4ce685a011eb.png

@icebob
Copy link
Member Author

icebob commented May 25, 2017

@jmverges Could you create a jsfiddle?

Copy link
Collaborator

@dflock dflock left a comment

Choose a reason for hiding this comment

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

Much better, thanks!

@icebob
Copy link
Member Author

icebob commented May 25, 2017

@dflock In d008869 a made simpler solution for fieldIdPrefix. Could you check it?

@icebob
Copy link
Member Author

icebob commented May 25, 2017

Further tasks before merge:

  • fix tests
  • cover with tests the new features
  • update docs

Somebody can help? At least with docs :)

@dflock
Copy link
Collaborator

dflock commented May 25, 2017

This looks good.

I'd still advocate calling it schema.fieldsets instead of schema.groups - because that automatically tells you what the feature does and what output you're going to get.

@jmverges
Copy link
Contributor

I would like to have that somehow configurable, or "hackable" somehow. Think about doing some tabs for each "fieldset" you may need to change the group rendering.

@icebob
Copy link
Member Author

icebob commented May 25, 2017

I think groups it's not bad. More simpler than fieldset. And we need to add it to docs, how it's working

@icebob
Copy link
Member Author

icebob commented May 25, 2017

In the future we can add tag to groups too and we can create not just <fieldset> -> <legend>, but even <section>-><header>.

@dflock
Copy link
Collaborator

dflock commented May 25, 2017

Ok, calling it groups is fine.

I think if I was doing multiple tabs, I'd probably do the tab markup outside of vfg and have multiple calls to vfg, one per tab, maybe? Haven't thought about it too deeply. What about multiple tabs, with groups/fieldsets on each tab? I think the groups thing should just do fieldsets for now - don't try and make it do everything.

@dflock
Copy link
Collaborator

dflock commented May 25, 2017

I'll start updating the docs now.

@icebob
Copy link
Member Author

icebob commented May 25, 2017

Thanks @dflock. Test fixed.

@icebob
Copy link
Member Author

icebob commented May 25, 2017

Just my thougths: In the future maybe would be good a visible property in groups (like in fields). Would be easy to turn on/off the whole group.

…ect property

Move core of `getFieldID` to utils
@dflock
Copy link
Collaborator

dflock commented May 25, 2017

OK, docs changes are done (I think), here: https://www.gitbook.com/book/icebob/vueformgenerator/changes/7

@jmverges
Copy link
Contributor

jmverges commented May 26, 2017

Good morning guys,

A lot of work you did!

@icebob removing "sync" removes the possibility to update the schema and get the form rebuild. did you try it?

Edit:
I think we need to be able to sync groups in the grouped option and fields in the non-grouped part.

Cheers

@icebob
Copy link
Member Author

icebob commented May 26, 2017

@dflock Thank you. I'm checking...

@jmverges I removed sync because it is not neccessary. It is sticked in from Vue 1.x. Because vfg stored validation errors in schema prop. I don't checked your updated schema problem. First, I'm waiting a fiddle from you. :)

@jmverges
Copy link
Contributor

jmverges commented May 26, 2017

How can I create a fiddle for Vue and Vue Form Generator? If you can provide me the barebones, I can put the code in there 👍

@icebob
Copy link
Member Author

icebob commented May 26, 2017

Fork it: https://jsfiddle.net/icebob/0mg1v81e/
And modify the JS to demonstrate your issue.
"Update" and send me the link

@jmverges
Copy link
Contributor

I don't get it running int fiddle but something like this https://jsfiddle.net/ym6dn8zd/1/

@icebob
Copy link
Member Author

icebob commented May 26, 2017

Now it's running, but what is the exact problem? https://jsfiddle.net/ym6dn8zd/4/

@jmverges
Copy link
Contributor

https://jsfiddle.net/ym6dn8zd/7/ I cannot reproduce it in there, weird

@jmverges
Copy link
Contributor

Forgot it, was my own problem, didn't see it

@dflock dflock mentioned this pull request May 31, 2017
@icebob icebob merged commit 79094fc into master May 31, 2017
@icebob icebob deleted the grouping branch May 31, 2017 09:07
@icebob icebob mentioned this pull request May 31, 2017
@icebob
Copy link
Member Author

icebob commented May 31, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants