Add an inline button to filed

81 views
Skip to first unread message

alessandro francia

unread,
Apr 10, 2014, 6:37:32 AM4/10/14
to backbon...@googlegroups.com
Hi,
I'm upgrading from backbone form 0.9 to the last version, is changed the way to use template (or maybe i used wrongly it before) 
bow my question is;
if i've this template

<form class="form-horizontal" role="form">
        <fieldset data-fields="userHomepage,userHomepageEnabled">
        </fieldset>
        <div data-fields="variable">   
        </div>
 </form>
with this schema:
 

var form = new Backbone.Form({
         schema: {
            userHomepage: {
                type: 'TextArea',
                editorAttrs: { style: 'height: 80px;width: 200px;', id: 'urlExternalPage'},
                title: $.i18n.prop('label.externalpage.url') + ' *',
                validators: [
                    {
                        type: 'required', message: $.i18n.prop('validation.required')
                    }
                ]
            },
            variable: {
                type: 'Select',
                options: [
                   ....//...
                ],
                editorAttrs: { style: 'width: 200px;', id: 'addUrlVariable'},
                fieldClass: 'col-sm-5',
                title: $.i18n.prop('label.externalpage.variable')
            },
            userHomepageEnabled: {
                type: 'Checkbox',
                editorAttrs: {"data-form": "uniform", id: 'userHomepageEnabled'},
                title: $.i18n.prop('label.externalpage.enablePage')
            }
        },
        template :  _.template($('#externalPageHomeTemplate').html())
    });




there is a way to add a custom button inline after the variable's select?
i'd like to add a button "add variable" 


how to do it?
thanks

Charles Davison

unread,
Apr 10, 2014, 6:52:09 AM4/10/14
to backbon...@googlegroups.com
It sounds like you'll want to create a custom editor for this.  They are actually pretty simple to create, see the docs here:



--
You received this message because you are subscribed to the Google Groups "Backbone-forms" group.
To unsubscribe from this group and stop receiving emails from it, send an email to backbone-form...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

alessandro francia

unread,
Apr 10, 2014, 8:21:42 AM4/10/14
to backbon...@googlegroups.com
there isn't a way to do it in the template?
i can add it after backbone form render with jQuery, i wold like to do it in the best way!

but i don't know how to have this situatione

Title   Select   Button 
 
all inline

Charles Davison

unread,
Apr 10, 2014, 8:29:11 AM4/10/14
to backbon...@googlegroups.com
You could do it in the template but the best way would probably be via a custom editor; that way you can handle the button click logic within the editor code.

alessandro francia

unread,
Apr 10, 2014, 8:37:59 AM4/10/14
to backbon...@googlegroups.com
because now it done in this way
after the render of form:

        $('.modal #addU...').parent().append('<a href="javascript:void(0)" class="btn btn-primary" id="_id1397126697561" style="margin-left: 25;"></a>');

but how to do it in the template?

Charles Davison

unread,
Apr 10, 2014, 9:18:21 AM4/10/14
to backbon...@googlegroups.com
To do it via the template you can either:
- edit the template for that field
- edit the main form template, but then you need to expand the HTML and use data-editors, something like this:

<form class="form-horizontal" role="form">
  <fieldset data-fields="userHomepage,userHomepageEnabled">
    <div>
      <label>User homepage</label>
      <div data-editors="userHomepage"></div>
      <a href="javascript:void(0)" class="btn btn-primary" id="_id1397126697561" style="margin-left: 25;"></a>
    </div>
    <div>
      <label>User homepage enabled</label>
      <div data-editors="userHomepage"></div>
    </div>
  </fieldset>
  <div data-fields="variable">   
  </div>
 </form>
Reply all
Reply to author
Forward
0 new messages