Open alemangui opened 10 years ago
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 < notifications@github.com> 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 https://github.com/powmedia/backbone-forms/issues/427.
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?
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"))
}
]
});
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.