mirror of
https://github.com/fspc/BikeShed-1.git
synced 2026-09-16 08:31:36 -04:00
Added submit js to bikes/new view
* Added displayFormErrors utility * Added 4th option to bike styles “OTHER”
This commit is contained in:
@@ -13,3 +13,4 @@
|
||||
//= require jquery
|
||||
//= require jquery_ujs
|
||||
//= require twitter/bootstrap/bootstrap-button
|
||||
//= require utils
|
||||
|
||||
@@ -1 +1,30 @@
|
||||
$('.btn').button();
|
||||
|
||||
$("#add_bike_submit").click(function(){
|
||||
|
||||
json_data = { bike: {
|
||||
serial_number: $("#serial_number").val(),
|
||||
bike_brand_id: parseInt($("#bike_brand_id").val()),
|
||||
shop_id: parseInt($("#shop_id").val()),
|
||||
model: $("#model").val(),
|
||||
bike_style_id: parseInt($('input[name=bike_style]:checked').val()),
|
||||
seat_tube_height: parseInt($("#seat_tube_height").val()),
|
||||
bike_condition_id: parseInt($('input[name=bike_condition]:checked').val()),
|
||||
bike_purpose_id: 1,
|
||||
bike_wheel_size_id: parseInt($("#bike_wheel_size_id").val()),
|
||||
}};
|
||||
|
||||
$.ajax({
|
||||
url: $("#add_bike_submit").data("url"),
|
||||
type: "POST",
|
||||
data: json_data,
|
||||
dataType: "json",
|
||||
success: function(data, status, xhr){
|
||||
//window.location = "";
|
||||
},
|
||||
error: function(data, status ){
|
||||
displayFormErrors(data.responseJSON);
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
function displayFormErrors(data){
|
||||
if( data.errors != undefined ){
|
||||
$.each( data.errors, function( field, errorMsg) {
|
||||
$("#"+field).parents(".control-group").addClass("error");
|
||||
$("#"+field).siblings(".help-block").html(errorMsg);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user