gitana / alpaca

Alpaca provides the easiest way to generate interactive HTML5 forms for web and mobile applications. It uses JSON Schema and simple Handlebars templates to generate great looking, dynamic user interfaces on top of Twitter Bootstrap, jQuery UI, jQuery Mobile and HTML5.
http://www.alpacajs.org
Other
1.29k stars 371 forks source link

Set Data Attributes for Select Field #679

Closed aenany-atmosphereiot closed 4 years ago

aenany-atmosphereiot commented 5 years ago

Dear Alpaca Team,

Thank you for developing this library, it has saved my team a ton of time building forms... I was wondering if you could include the option to insert data attributes for Select Fields, in a similar fashion to the TextFields, for example:

under alpaca.options.fields:

firstName: {
    title: "First Name"
    type: "text",
    required: true,
    data: {
        example: 'dataExampleValue'
    }
}

I would also like this to be possible:

preference: {
    title: "Preference"
    type: "select",
    required: true,
    data: {
        example: 'dataExampleValue'
    }
}

Thank you so much.

seseso commented 5 years ago

You could edit the select template used by alpaca and add the same code as existing for text field: {{#each options.data}}data-{{@key}}="{{this}}"{{/each}}

You can have a look in the Templates section of the Views page: http://alpacajs.org/docs/api/views.html