Has anyone created a form and submitted the results using Ruby on Rails? I have successfully created the form but I cannot figure out how to submit back to a controller. Tried send() but was unsuccessful.
Hello,
you can put your
into for example, and then: myform.attachEvent(“onButtonClick”, function(name, command){ if(name==“commit”){ document.getElementById(“myForm”).submit();…Thanks for the reply. That works perfectly. The final working code is below.
Now I would like to attach this form to a layout and bring it up by selecting a menu. However, when I attach it, the form tag ends up empty and the form items end up in the Layouts Div.
How can I attach the form and retain the form tag in the proper place?
<div style=
Now I would like to attach this form to a layout and bring it up by selecting a menu.
The code snippet that you provided doesn’t contain layout initialization and doesn’t demonstrates how the form is attached to the layout cell.
Could you provide a complete demo ?
I believe I have found a workaround by wrapping the form tag around the layout div. But what happens when I want to have multiple forms appear in the same part of the layout? Do I need to use separate windows?
Here is the code and the menu structure builder and form builder built with Ruby on Rails.
<script type="text/javascript" charset="utf-8">
var layout,menu,grid, loginform;
dhtmlxEvent(window,“load”,function(){
layout = new dhtmlXLayoutObject(“parentID”, “1C”);
layout.cells(“a”).setText("");
layout.cells(“a”).setWidth(900);
menu = layout.attachMenu();
menu.attachEvent("onClick", menuClick);
menu.setIconsPath("icons/");
menu.loadXML("menu_data");
function menuClick(id){
switch (id) {
case "memberlist":
layout.cells("a").setText("Membership List");
grid = layout.cells("a").attachGrid();
grid.setImagePath("/images/imgs/");
grid.setHeader("Club Name, Last Name, First Name, Business Phone, Home Phone, Preferred E-Mail");
grid.setInitWidths("*,*,*,*,*,*");
grid.attachHeader("#text_filter,#text_filter,#text_filter,#rspan,#rspan,#rspan");
grid.setColAlign("left,left,left,left,left,left");
grid.setColTypes("link,link,link,ro,ro,ro");
grid.setColSorting("str,str,str,str,str,str");
grid.setSkin("dhx_skyblue");
//grid.groupBy(0);
grid.init();
grid.enableSmartRendering(true);
grid.attachEvent("onXLS",function(){
//show loading cursor
document.getElementById("parentID").style.cursor = "wait";
document.body.style.cursor = "wait";
})
grid.attachEvent("onXLE",function(){
//Reset Cursor
document.getElementById("parentID").style.cursor = "default";
})
grid.load("members_data");
break;
case "newmember":
layout.cells("a").setText("Add New Member");
document.write(new_member_path);
break;
case "memberpositions":
layout.cells("a").setText("Membership by Positions");
grid = layout.cells("a").attachGrid();
grid.setImagePath("/images/imgs/");
grid.csv.row = "\n";
grid.csv.cell = ",";
grid.setHeader("Year,Type,Position,Chair,Club,Last Name,First Name,Business Phone,Home Phone,Preferred E-Mail");
grid.setInitWidths("*,*,255,*,140,100,100,100,100,175");
grid.attachHeader("#select_filter,#select_filter,#select_filter_strict,#select_filter,#combo_filter,#text_filter,#text_filter,#text_filter,#text_filter,#text_filter");
grid.setColAlign("center,center,left,center,left,left,left,left,left,left");
grid.setColTypes("ro,ro,ro,ro,ro,link,link,ro,ro,ro");
grid.setColSorting("str,str,str,na,str,str,str,str,str,str");
grid.setSkin("dhx_skyblue");
grid.editStop();
grid.enableCSVHeader(true);
grid.attachEvent("onXLS",function(){
//show loading cursor
document.getElementById("parentID").style.cursor = "wait";
document.body.style.cursor = "wait";
})
grid.attachEvent("onXLE",function(){
//Reset Cursor
document.getElementById("parentID").style.cursor = "default";
})
grid.enableSmartRendering(true);
grid.setColumnsVisibility("false,false,false,false,false,false,false,true,true,false");
grid.load("positions_filter_data");
grid.init()
break;
case "login":
loginform = layout.cells("a").attachForm("");
loginform.loadStruct("/form_data/");
loginform.attachEvent("onButtonClick", function(name, command){
if(name=="commit"){
document.getElementById("new_member_session").submit();
}
});
break;
} //end switch
} //end click function
}) //end load function
######## menu builder #############
xml.instruct!
xml.tag!(“menu”) do
xml.tag!("item", :id => "members", :text => "Members" ) do
xml.tag!("item", :id => "memberlist", :text => "Member List" )
xml.tag!("item", :id => "memberpositions", :text => "Members by Positions" )
if permitted_to? :create, @members
xml.tag!("item", :id => "newmember", :text=> "Add New Member") do
xml.href(:target => "blank") do
xml.cdata!(new_member_path(@member))
end
end
end
end
xml.tag!("item", :id => "leadership", :text => "Leadership" ) do
xml.tag!("item", :id => "districtleaders", :text => "Leadership List" )
xml.href(link_to "District Leadership" , leadership_index_path)
end
xml.tag!("item", :id => "clubs", :text => "Clubs" ) do
xml.tag!("item", :id => "clublist", :text => "Club List" )
end
xml.tag!("item", :id => "login", :text=> "log in")
end
########### Form Builder ###################
xml.instruct!
xml.tag!(“form”) do
xml.tag!(“items”) do
xml.tag!(“item”, :type => “input:”,
:name => “authenticity_token”,
:type => “hidden”,
:value => form_authenticity_token)
xml.tag!(“item”, :type => “label”, :label => “Login with your e-mail address”)
xml.tag!(“item”, :type => “input”,
:label => “E-mail”,
:value => “”,
:name => “member_session[preferred_email]”,
:id =>“member_session_preferred_email”)
xml.tag!(“item”, :type => “label”, :label => “Password”)
xml.tag!(“item”, :type => “password”,
:name => “member_session[password]”,
:value => “”,
:id => “member_session_password”)
xml.tag!(“item”, :type => “input”,
:name => “member_session[remember_me]”,
:type => “hidden”,
:value =>“1”)
xml.tag!(“item”, :type => “checkbox”,
:name => “member_session[remember_me]”,
:label => “Remember me”,
:checked => “false”,
:id => “member_session_remember_me”)
xml.tag!(“item”, :type => “button”,
:name => “commit”,
:value => “Login”,
:command => member_session_path,
:id => “member_session_submit”)
end
end