Fixed issue with dynamic checkboxes

This commit is contained in:
Ziver Koc 2017-03-13 18:07:29 +01:00
parent 9af96a7cb2
commit b5024a063d
3 changed files with 33 additions and 11 deletions

View file

@ -118,10 +118,17 @@
$.each(button.attr(), function(fieldName, value) { $.each(button.attr(), function(fieldName, value) {
if(fieldName.startsWith("data-")) { if(fieldName.startsWith("data-")) {
fieldName = fieldName.substring(5); fieldName = fieldName.substring(5);
// case insensitive search input = modal.find("input").filter(function() {
modal.find("input").filter(function() {
return this.name.toLowerCase() == fieldName; return this.name.toLowerCase() == fieldName;
}).val(value); });
if (input.attr("type") == "checkbox") { // special handling for checkboxes
if (value=="true") input.attr("checked", "true");
else input.removeAttr("checked", "true");
// Add default false value as a unchecked checkbox is not included in the post
input.parent().prepend("<input type='hidden' name='"+input.attr("name")+"' value='false' />");
} else {
input.val(value);
}
} }
}); });
}); });
@ -174,7 +181,7 @@
<label class="control-label">{{.getNiceName()}}:</label> <label class="control-label">{{.getNiceName()}}:</label>
{{#.isTypeString()}}<input type="text" class="form-control" name="{{.getName()}}">{{/#.isTypeString()}} {{#.isTypeString()}}<input type="text" class="form-control" name="{{.getName()}}">{{/#.isTypeString()}}
{{#.isTypeInt()}}<input type="number" class="form-control" name="{{.getName()}}">{{/#.isTypeInt()}} {{#.isTypeInt()}}<input type="number" class="form-control" name="{{.getName()}}">{{/#.isTypeInt()}}
{{#.isTypeBoolean()}}<input type="checkbox" name="{{.getName()}}">{{/#.isTypeBoolean()}} {{#.isTypeBoolean()}}<input type="checkbox" name="{{.getName()}}" value="true">{{/#.isTypeBoolean()}}
{{#.isTypeEnum()}} {{#.isTypeEnum()}}
<select class="form-control" name="{{.getName()}}"> <select class="form-control" name="{{.getName()}}">
{{#.getPossibleValues()}}<option>{{.}}</option>{{/.getPossibleValues()}} {{#.getPossibleValues()}}<option>{{.}}</option>{{/.getPossibleValues()}}

View file

@ -226,10 +226,17 @@
if(fieldName.startsWith("data-")) { if(fieldName.startsWith("data-")) {
fieldName = fieldName.substring(5); fieldName = fieldName.substring(5);
console.log(fieldName, value); console.log(fieldName, value);
// case insensitive search input = modal.find("input").filter(function() {
modal.find("input").filter(function() {
return this.name.toLowerCase() == fieldName; return this.name.toLowerCase() == fieldName;
}).val(value); });
if (input.attr("type") == "checkbox") { // special handling for checkboxes
if (value=="true") input.attr("checked", "true");
else input.removeAttr("checked", "true");
// Add default false value as a unchecked checkbox is not included in the post
input.parent().prepend("<input type='hidden' name='"+input.attr("name")+"' value='false' />");
} else {
input.val(value);
}
} }
}); });
}); });
@ -306,7 +313,7 @@
<label class="control-label">{{.getNiceName()}}:</label> <label class="control-label">{{.getNiceName()}}:</label>
{{#.isTypeString()}}<input type="text" class="form-control" name="{{.getName()}}">{{/#.isTypeString()}} {{#.isTypeString()}}<input type="text" class="form-control" name="{{.getName()}}">{{/#.isTypeString()}}
{{#.isTypeInt()}}<input type="number" class="form-control" name="{{.getName()}}">{{/#.isTypeInt()}} {{#.isTypeInt()}}<input type="number" class="form-control" name="{{.getName()}}">{{/#.isTypeInt()}}
{{#.isTypeBoolean()}}<input type="checkbox" name="{{.getName()}}">{{/#.isTypeBoolean()}} {{#.isTypeBoolean()}}<input type="checkbox" name="{{.getName()}}" value="true">{{/#.isTypeBoolean()}}
{{#.isTypeEnum()}} {{#.isTypeEnum()}}
<select class="form-control" name="{{.getName()}}"> <select class="form-control" name="{{.getName()}}">
{{#.getPossibleValues()}}<option>{{.}}</option>{{/.getPossibleValues()}} {{#.getPossibleValues()}}<option>{{.}}</option>{{/.getPossibleValues()}}

View file

@ -171,9 +171,17 @@
fieldName = fieldName.substring(5); fieldName = fieldName.substring(5);
console.log(fieldName, value); console.log(fieldName, value);
// case insensitive search // case insensitive search
modal.find("input").filter(function() { input = modal.find("input").filter(function() {
return this.name.toLowerCase() == fieldName; return this.name.toLowerCase() == fieldName;
}).val(value); });
if (input.attr("type") == "checkbox") { // special handling for checkboxes
if (value=="true") input.attr("checked", "true");
else input.removeAttr("checked", "true");
// Add default false value as a unchecked checkbox is not included in the post
input.parent().prepend("<input type='hidden' name='"+input.attr("name")+"' value='false' />");
} else {
input.val(value);
}
} }
}); });
}); });
@ -280,7 +288,7 @@
<label class="control-label">{{.getNiceName()}}:</label> <label class="control-label">{{.getNiceName()}}:</label>
{{#.isTypeString()}}<input type="text" class="form-control" name="{{.getName()}}">{{/#.isTypeString()}} {{#.isTypeString()}}<input type="text" class="form-control" name="{{.getName()}}">{{/#.isTypeString()}}
{{#.isTypeInt()}}<input type="number" class="form-control" name="{{.getName()}}">{{/#.isTypeInt()}} {{#.isTypeInt()}}<input type="number" class="form-control" name="{{.getName()}}">{{/#.isTypeInt()}}
{{#.isTypeBoolean()}}<input type="checkbox" name="{{.getName()}}">{{/#.isTypeBoolean()}} {{#.isTypeBoolean()}}<input type="checkbox" name="{{.getName()}}" value="true">{{/#.isTypeBoolean()}}
{{#.isTypeEnum()}} {{#.isTypeEnum()}}
<select class="form-control" name="{{.getName()}}"> <select class="form-control" name="{{.getName()}}">
{{#.getPossibleValues()}}<option>{{.}}</option>{{/.getPossibleValues()}} {{#.getPossibleValues()}}<option>{{.}}</option>{{/.getPossibleValues()}}