Skip to content
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

Specify individual fieldsets in templates #427

Open
alemangui opened this issue Oct 20, 2014 · 3 comments
Open

Specify individual fieldsets in templates #427

alemangui opened this issue Oct 20, 2014 · 3 comments

Comments

@alemangui
Copy link
Contributor

Hello,

I was wondering if the possibility of specifying a particular fieldset in the templates is something desirable/planned. The idea would be something along the lines of:

<div data-fieldsets="personalData"></div>

while keeping the possibility of doing

<div data-fieldsets></div>

which would place all fieldsets - as before.

Additionally, by being able to individually name the fieldsets, we can use custom templates for the fieldset itself. The advantage would be to gain flexibility on the custom templates.

I have noticed that during the render of the Form there is a search for the [data-editors], [data-fields] and [data-fieldsets], but while the editors and the fields are key-value objects, the fieldsets are an array, making each element anonymous.

An option would be to make the fieldsets a key-value object as well, or introduce another concept of something like a named-fieldset.

If this sounds like something that could interest you I could try preparing a pull request.

@powmedia
Copy link
Owner

The fieldsets are arrays in part because this guarantees the order they
will come out in when rendered in the browser since some browsers can mix
the order of object keys.

On Mon, Oct 20, 2014 at 3:03 PM, Alejandro Mantecon-Guillen <
[email protected]> wrote:

Hello,

I was wondering if the possibility of specifying a particular fieldset in
the templates is something desirable/planned. The idea would be something
along the lines of:

while keeping the possibility of doing

which would place all fieldsets - as before.

Additionally, by being able to individually name the fieldsets, we can use
custom templates for the fieldset itself. The advantage would be to gain
flexibility on the custom templates.

I have noticed that during the render of the Form there is a search for
the [data-editors], [data-fields] and [data-fieldsets], but while
the editors and the fields are key-value objects, the fieldsets are an
array, making each element anonymous.

An option would be to make the fieldsets a key-value object as well, or
introduce another concept of something like a named-fieldset.

If this sounds like something that could interest you I could try
preparing a pull request.

Reply to this email directly or view it on GitHub
#427.

@alemangui
Copy link
Contributor Author

What about adding the possibility of specifying in the fieldset not only the legend and fields but also the name and template? The we could use this name attribute to reference the fieldset.

model.fieldsets = [{
   legend: 'from model',
   fields: ['fromModel'],
   name: 'modelFieldset',
   template: <some template if needed>
}, {...}, {...}];
<div data-fieldsets="modelFieldset"></div>

and the fieldset template to personalize it.

Would this be more reasonable?

@quayle
Copy link

quayle commented Mar 8, 2022

Memento for anybody whom is using this library (just like me).

Example how to personalize fieldsets using different templates:

let schema = {};/// your schema
let model = new Backbone.Model({});
let form = new Form({
        model: model,
        schema: schema,
        fieldsets: [
            {
                fields: [
                    'field1',
                    'field2',
                    'field3'
                ],
                template: _.template([
                    '<div class="class1" data-fields></div>',
                ].join("\n"))
            },
            {
                fields: [
                    'field4',
                    'field5',
                    'field6'
                ],
                template: _.template([
                    '<div class="class2" data-fields></div>',
                ].join("\n"))
            }
        ]
    });

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

No branches or pull requests

3 participants