1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
var AddressView = SerializableView.extend({
template: $("#address_template").html(),
events: {
},
initialize: function(opt){
this.parent = opt.parent
this.setElement( this.parent.$(".address") )
this.$el.html(this.template)
},
populate: function(data){
this.data = data
var address = data.Address.split("\n")
data.Address1 = address[0]
data.Address2 = address[1]
this.$(".address input").val("")
this.load_data(data)
},
validate_presence: {
"Name": "Please enter your first name.",
"Surname": "Please enter your last name.",
"Address1": "Please enter your street address.",
"City": "Please enter your city.",
"Phone": "Please enter your phone number.",
},
validate_fields: function(data, errors){
if (data.Phone.replace(/[^0-9]/g, "").length < 10) { errors.push([ "Phone", "Phone numbers must be at least 10 digits." ]) }
if (! data.Province || data.Province == "NONE") { errors.push([ "Province", "Please choose your state." ]) }
data.Address = data.Address1 + "\n" + data.Address2
data.UserId = auth.user_id
delete data.Address1
delete data.Address2
},
})
|