EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: poeziafree on February 18, 2022, 07:39:00 AM



Title: Programmatically Construct Form within Window
Post by: poeziafree on February 18, 2022, 07:39:00 AM
Hello

I create the Window using javascript through this code:

Code:
$('#win').window({
    width:600,
    height:400,
    modal:true
});

Now I need to create the form inside this window content. But I don't want to load the html form using ajax call from server.

Is there any way to programmatically create the form with its fields and submit function and append that to the window content?

Thank you very much in advance!


Title: Re: Programmatically Construct Form within Window
Post by: jarry on February 21, 2022, 01:39:07 AM
Please refer to the code below.
Code:
$('#win').window({
width: 400,
height: 400,
modal: true
});
var f = $('<form style="padding:20px"></form>').appendTo('#win');
var wrap = $('<div style="margin-bottom:20px"></div>').appendTo(f);
var field = $('<input name="name" style="width:100%">').appendTo(wrap).textbox({
label: 'Name:',
required: true
});
wrap = $('<div style="margin-bottom:20px"></div>').appendTo(f);
field = $('<input name="email" style="width:100%">').appendTo(wrap).textbox({
label: 'Email:',
required: true,
validType: 'email'
});
var bar = $('<div style="text-align:center"></div>').appendTo(f);
var btn = $('<a href="javascript:;">Submit</a>').appendTo(bar).linkbutton({
width: 100,
onClick: function(){
f.form('submit')
}
})