Home>

demand:As shown below,When "t" is selected as the [Primary Key], "t" cannot be selected for [Allow Null], and it will be automatically switched to "f";

When [Allow Null] is selected as "t", determine whether [Primary Key] is Null,If it is "t", a prompt pops up,Not change

First you need to add a switch control to the table:

Define the primary key:define the control format in the form of a temple template,Where {{d.isserial == "t"?"checked":""}} sets the default value for it

{field:"isserial", title:"Primary Key", minwidth:120, templet:"#switchtpl", unresize:true}
<!-Define whether the primary key is a switch->
<script type="text/html">
<!-The checked status here is->
<input type="checkbox" name="ifkey" value={{d.colno}} lay-skin="switch" lay-text="t | f" lay-filter="ifkeydemo" {{d.isserial == "t"?"checked":""}}>
</script>

Definition is allowed to be empty:

{field:"notnull", title:"Allow to be empty", minwidth:100, templet:"#switchnulltpl", unresize:true}
<!-Defines whether to allow null switches->
<script type="text/html">
<input type="checkbox" name="ifnull" value="{{d.colno}}" lay-skin="switch" lay-text="t | f" lay-filter="ifnulldemo" {{d .notnull == "t"?"checked":""}}>
</script>

Add listener:listen for the primary key,lay-filter way to add listeners,The key part is

//Assign a value to the object's primary key
tabledata [parenttrindex] .isserial="t";
//Get divs allowed to be empty
var switchifnull=$(parenttr) .find ("td:eq (6)"). find ("div:eq (1)");
//Change the style of div to f, the value of f
switchifnull.prop ("class", "layui-unselect layui-form-switch");//f's style
switchifnull.find ("em"). text ("f");//value of f
tabledata [parenttrindex] .notnull="f";//Modify the value of f in the data

layer.lips ("This column is the primary key.Not allowed to be empty ", obj.othis);//tips

//primary key
 form.on ("switch (ifkeydemo)", function (obj) {
//Get the current control
var selectifkey=obj.othis;
//Get the current line
var parenttr=selectifkey.parents ("tr");
//Get the index of the current row
var parenttrindex=parenttr.attr ("data-index");
if (obj.elem.checked == true) {//is the primary key
//Assign a value to the object's primary key
tabledata [parenttrindex] .isserial="t";
//Get divs allowed to be empty
var switchifnull=$(parenttr) .find ("td:eq (6)"). find ("div:eq (1)");
//Change the style of div to f, the value of f
switchifnull.prop ("class", "layui-unselect layui-form-switch");//f's style
switchifnull.find ("em"). text ("f");
tabledata [parenttrindex] .notnull="f";
layer.lips ("This column is the primary key.
Not allowed to be empty ", obj.othis);
} else {
//Assign values ​​to objects
tabledata [parenttrindex] .isserial="f";
}
});

Add listener:listener [allow empty], similarly

//allow empty
form.on ("switch (ifnulldemo)", function (obj) {
//Get the current control
var selectifkey=obj.othis;
//Get the current line
var parenttr=selectifkey.parents ("tr");
//Get the index of the current row
var parenttrindex=parenttr.attr ("data-index");
//Get the value of "is the primary key"
var ifkey=parenttr.find (("td:eq (2)")). text (). trim ();
if (ifkey == "t") {
//Assign values ​​to objects
//Get divs allowed to be empty
var switchifnull=$(parenttr) .find ("td:eq (6)"). find ("div:eq (1)");
//Change the style of div to f, the value of f
switchifnull.prop ("class", "layui-unselect layui-form-switch");//f's style
switchifnull.find ("em"). text ("f");
tabledata [parenttrindex] .notnull="f";
layer.alert ("This column is the primary key.
Not allowed to be empty;
To be empty,Please change the primary key ");
} else {
if (obj.elem.checked == true) {//Allow empty
//Assign values ​​to objects
tabledata [parenttrindex] .notnull="t";
} else {
//Assign values ​​to objects
tabledata [parenttrindex] .notnull="f";
}
}
});
  • Previous How to provide persistent history for a Python terminal
  • Next Detailed springboot configuration redis process