some bugfixes
This commit is contained in:
parent
7e3305bea2
commit
9bd7ca9d6c
1 changed files with 15 additions and 13 deletions
|
|
@ -1,41 +1,43 @@
|
||||||
<script>
|
<script>
|
||||||
$(function(){
|
$(function(){
|
||||||
initDynamicModalForm("action");
|
initDynamicModalForm("actionModal", "action-data-conf", "data-conf-template");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
var dynamicConf = {};
|
var dynamicConf = {};
|
||||||
|
|
||||||
function initDynamicModalForm(name){
|
function initDynamicModalForm(modalId, formTemplateId, templateID){
|
||||||
// read in all configurations into global variable (to skip naming issues)
|
// read in all configurations into global variable (to skip naming issues)
|
||||||
dynamicConf[name] = [];
|
dynamicConf[formTemplateId] = [];
|
||||||
$("#"+name+"-data-conf-template div").each(function(){
|
$("#"+templateID+" div").each(function(){
|
||||||
dynamicConf[name][$(this).attr("id")] = $(this).html();
|
dynamicConf[formTemplateId][$(this).attr("id")] = $(this).html();
|
||||||
});
|
});
|
||||||
// Update dynamic inputs
|
// Update dynamic inputs
|
||||||
$("#"+name+"Modal select[name=type]").change(function(){
|
$("#"+modalId+" select[name=type]").change(function(){
|
||||||
$("#"+name+"Modal #"+name+"-data-conf").html(dynamicConf[name][$(this).val()]);
|
$("#"+modalId+" #"+formTemplateId).html(dynamicConf[formTemplateId][$(this).val()]);
|
||||||
});
|
});
|
||||||
// click event
|
// click event
|
||||||
$("#"+name+"Modal").on('show.bs.modal', function (event) {
|
$("#"+modalId).on('show.bs.modal', function (event) {
|
||||||
var button = $(event.relatedTarget);
|
var button = $(event.relatedTarget);
|
||||||
var modal = $(this);
|
var modal = $(this);
|
||||||
modal.find("input").val(""); // Reset all inputs
|
// Reset all inputs
|
||||||
|
modal.find("#"+formTemplateId).empty(); // clear form div
|
||||||
|
|
||||||
|
// select dynamic form
|
||||||
|
var selector = modal.find("select[name=type]");
|
||||||
|
selector.val(button.data("type"));
|
||||||
|
selector.change(); // Update dynamic inputs
|
||||||
// set dynamic form data
|
// set dynamic form data
|
||||||
modal.find("select[name=type]").val(button.data("type"));
|
|
||||||
modal.find("select[name=type]").change(); // Update dynamic inputs
|
|
||||||
$.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);
|
||||||
console.log(fieldName, value);
|
|
||||||
// case insensitive search
|
// case insensitive search
|
||||||
input = modal.find("input").filter(function() {
|
input = modal.find("input").filter(function() {
|
||||||
return this.name.toLowerCase() == fieldName;
|
return this.name.toLowerCase() == fieldName;
|
||||||
});
|
});
|
||||||
if (input.attr("type") == "checkbox") { // special handling for checkboxes
|
if (input.attr("type") == "checkbox") { // special handling for checkboxes
|
||||||
if (value=="true") input.attr("checked", "true");
|
if (value=="true") input.attr("checked", "true");
|
||||||
else input.removeAttr("checked", "true");
|
else input.removeAttr("checked");
|
||||||
// Add default false value as a unchecked checkbox is not included in the post
|
// 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' />");
|
input.parent().prepend("<input type='hidden' name='"+input.attr("name")+"' value='false' />");
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue