Use the submit button option

64 views
Skip to first unread message

Jacob Phillips

unread,
Jul 13, 2015, 3:18:11 PM7/13/15
to backbon...@googlegroups.com
Reading here, in the docs that you can just add 'submitButton: "Submit Text"' to options and you'll get a button. 

    var User = Backbone.Model.extend({
        schema: {
            title: { type: 'Select', options: ['', 'Mr', 'Mrs', 'Ms'] },
            name: { type: 'Text', validators: ['required', 'message:hey_bud'] },
            email: { validators: ['required', 'email'] },
            birthday: 'Date',
            password: 'Password',
            address: {
                type: 'Object',
                subSchema: {
                    street: {},
                    zip: { type: 'Number' },
                    country: { type: 'Select', options: ['Japan', 'Mongolia'] }
                }
            },
            Radios: { type: 'Radio', options: { value1: '<b>trial</b>', value2: 'standard' }, validators: ['required'] }

        }

});

   
var user = new User({
        title
: 'Mr',
        name
: 'Sterling Archer',
        email
: 'ster...@isis.com',
        birthday
: new Date(1978, 6, 12),
        password
: 'dangerzone',


   
});


   
var form = new Backbone.Form({
            model
: user,
            submitButton
: "Submit Btn Text"
   
}).render();


   
<script id="formTemplate" type="text/html">
       
<form>
           
<h1>New User</h1>


            <h2>Main Info</
h2>
           
<div data-fields="title,name,birthday,address"></div>


           
<h2>Account Info</h2>
            <h3>Email</
h3>
           
<div data-fields="email"></div>


           
<h3>Password</h3>
            <p>Must be at least 8 characters long</
p>
           
<div data-editors="password"></div>
           
           
<h3>Actions</h3>


        </
form>
   
</script>



It all works with no error, but no button. Am I missing something simple? 


Charles Davison

unread,
Jul 14, 2015, 6:49:16 AM7/14/15
to backbon...@googlegroups.com

If you're using that custom form template then that could be the reason - you'd need to include this part (from the original form template):

https://github.com/powmedia/backbone-forms/blob/master/src/templates/bootstrap3.js#L8-L10


--
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.

Jacob Phillips

unread,
Jul 14, 2015, 3:28:35 PM7/14/15
to backbon...@googlegroups.com
Yes I am (I should have included that in what I posted, sorry): 
        template: _.template($('#formTemplate').html()),

I tried adding it to my form:

<% if (submitButton) { %>\
 
<button type="submit" class="btn"><%= submitButton %></button>\
<% } %>\

But I get: 

ReferenceError:submitButton is not defined. 

I have to add a bunch of buttons so I'll just add/hide them directly. 


Reply all
Reply to author
Forward
0 new messages