PDA

View Full Version : [CLOSED] GridPanel + FormPanel insert record with boolean columns



John_Writers
May 22, 2013, 7:21 AM
Hi,
I have a problem when I insert a new record with boolean value inside.

I have two javascript funtions:
updateRecord(form) -> this function update the edited record and works well with all field type.
addRecord(form,grid) -> this function insert a new record with the value inserted by the user in the form. Here is the problem, when I insert record with boolean fields the getValues() function make this assignment values[withoutPrefixName] = val; (with val equals to 'App.CPH_Center_Enabled').

I think this is a misconfiguration problem..

I don't have this problem with updateRecord function..

Thank you for your help.

Here above the simplified code:


<asp:Content ID="Content2" ContentPlaceHolderID="CPH_Center" runat="server">
<script type="text/javascript" language="javascript">

var addRecord = function (form, grid) {
if (!form.getForm().isValid()) {
Ext.net.Notification.show({
iconCls : "icon-exclamation",
html : "Form is invalid",
title : "Error"
});

return false;
}

grid.store.insert(0, new BadgeReader(form.getForm().getValues()));
form.getForm().reset();
};

var updateRecord = function (form) {
if (form.getForm()._record == null) {
return;
}

if (!form.getForm().isValid()) {
Ext.net.Notification.show({
iconCls : "icon-exclamation",
html : "Form is invalid",
title : "Error"
});
return false;
}

form.getForm().updateRecord(form.getForm()._record[0]);
};


</script>

<ext:Store ID="st_BadgeReaders" runat="server" AutoLoad="true" AutoSync="true">
<Proxy>
<ext:AjaxProxy>
<ActionMethods Read="GET">
</ActionMethods>
<API
Read="../WebService/WCF_DataAccess.svc/GetBadgeReaders"
Create="../WebService/WCF_DataAccess.svc/AddBadgeReader"
Update="../WebService/WCF_DataAccess.svc/UpdateBadgeReader" />
<Reader>
<ext:JsonReader Root="d">
</ext:JsonReader>
</Reader>
<Writer>
<ext:JsonWriter Root="d" Encode="true" />
</Writer>
</ext:AjaxProxy>
</Proxy>
<Model>
<ext:Model ID="mdlBadgeReader" runat="server" IDProperty="ID_BADGE_READER" Name="BadgeReader">
<Fields>
<ext:ModelField Name="ID_BADGE_READER" Type="Int" />
<ext:ModelField Name="Name" Type="String" />
<ext:ModelField Name="Description" Type="String" />
<ext:ModelField Name="IPADDRESS" Type="String" Mapping="IPADDRESS" />
<ext:ModelField Name="Enabled" Type="Boolean" Mapping="Enabled" />

</Fields>
</ext:Model>
</Model>
<Listeners>
<Exception Handler="
var error = operation.getError(),
message = Ext.isString(error) ? error : ('(' + error.status + ')' + error.statusText);
Ext.net.Notification.show({
iconCls : 'icon-exclamation',
html : message,
title : 'EXCEPTION',
autoScroll : true,
hideDelay : 10000,
width : 300,
height : 200
});" />
</Listeners>
</ext:Store>
<ext:GridPanel ID="gp_BadgeReaders" runat="server" StoreID="st_BadgeReaders" Title="table"
Height="600" Flex="1" Region="Center" MultiSelect="false" AllowDeselect="false">
<ColumnModel ID="ColumnModel1" runat="server">
<Columns>
<ext:Column runat="server" ColumnID="ID_BADGE_READER" DataIndex="ID_BADGE_READER" Hidden="true" />
<ext:Column runat="server" ColumnID="Name" Header="Name"
Locked="true" DataIndex="Name" />
<ext:Column runat="server" ColumnID="Description" Header="Description"
Align="Left" DataIndex="Description" />
<ext:Column runat="server" ColumnID="IPADDRESS" Header="IP Address"
Align="Left" DataIndex="IPADDRESS" />
<ext:CheckColumn runat="server" Width="60" ColumnID="Enabled" Header="Enabled"
DataIndex="Enabled" />


</Columns>
</ColumnModel>
<SelectionModel>
<ext:RowSelectionModel ID="RowSelectionModel1" runat="server" Mode="Single">
<Listeners>
<Select Handler="
#{frmBadgeReader}.getForm().loadRecord(record);
#{btnEdit}.show();

" />
<Deselect Handler="
#{btnEdit}.hide();
" />
</Listeners>
</ext:RowSelectionModel>
</SelectionModel>
<Buttons>
<ext:Button ID="btnAdd" Icon="ApplicationAdd" Text="Add New"
runat="server" OnClientClick="
#{frmBadgeReader}.getForm().reset();
#{btnAddSave}.setVisible(true);
#{btnUpdateSave}.setVisible(false);
#{wndAddNew}.show();">
</ext:Button>
<ext:Button ID="btnEdit" Icon="ApplicationEdit" Hidden="true" Text="Edit Selected"
runat="server" OnClientClick="

#{frmBadgeReader}.loadRecord(#{gp_BadgeReaders}.ge tSelectionModel().getSelection());
#{btnAddSave}.setVisible(false);
#{btnUpdateSave}.setVisible(true);
#{wndAddNew}.show();">
</ext:Button>
</Buttons>
</ext:GridPanel>
<ext:Window ID="wndAddNew" runat="server" Icon="Application" Height="500"
Width="600" BodyPadding="5" Modal="true" Hidden="true" AutoScroll="true" BodyStyle="background-color: #fff;" >
<Content>
<ext:FormPanel ID="frmBadgeReader" runat="server" Header="false" Padding="5" ButtonAlign="Right">
<Items>
<ext:FieldSet ID="fsBadgeReaderDescription" runat="server" ColumnWidth="0.4" Title="Information"
MarginSpec="0 0 0 10" ButtonAlign="Right" Layout="TableLayout">
<LayoutConfig>
<ext:TableLayoutConfig Columns="1" />
</LayoutConfig>
<Defaults>
<ext:Parameter Name="Width" Value="300" />
<ext:Parameter Name="LabelWidth" Value="150" />
</Defaults>
<Items>
<ext:Hidden ID="hidID_BadgeReader" Name="ID_BADGE_READER" runat="server" />
<ext:TextField ID="txtName" Name="Name" runat="server" FieldLabel="Name"
MaxLengthText="100" AllowBlank="false" />
<ext:TextField ID="txtDescription" Name="Description" runat="server" FieldLabel="Description"
MaxLengthText="400" />
</Items>
</ext:FieldSet>

<ext:FieldSet ID="fsAddress" runat="server" ColumnWidth="0.4" Title="adress section"
MarginSpec="0 0 0 10" ButtonAlign="Right" Layout="TableLayout">
<LayoutConfig>
<ext:TableLayoutConfig Columns="1"></ext:TableLayoutConfig>
</LayoutConfig>
<Defaults>
<ext:Parameter Name="Width" Value="300" />
<ext:Parameter Name="LabelWidth" Value="150" />
</Defaults>
<Items>
<ext:TextField ID="txtADDRESS_IP" Name="IPADDRESS" runat="server" FieldLabel="IP Address" />

</Items>
</ext:FieldSet>

<ext:FieldSet ID="fsBadgeReaderManagement" runat="server" ColumnWidth="0.4" Title="management"
MarginSpec="0 0 0 10" ButtonAlign="Right" Layout="TableLayout">
<LayoutConfig>
<ext:TableLayoutConfig Columns="1"></ext:TableLayoutConfig></LayoutConfig>
<Defaults>
<ext:Parameter Name="Width" Value="300" />
<ext:Parameter Name="LabelWidth" Value="150" />
</Defaults>
<Items>
<ext:Checkbox ID="Enabled" Name="Enabled" runat="server" FieldLabel="enabled" />

</Items>
</ext:FieldSet>
</Items>
<Buttons>
<ext:Button ID="btnAddSave" runat="server" Text="addsave"
Icon="Disk">
<Listeners>
<Click Handler="
addRecord(#{frmBadgeReader}, #{gp_BadgeReaders});
#{wndAddNew}.setVisible(false);
#{st_BadgeReaders}.load();
" />
</Listeners>
</ext:Button>
<ext:Button ID="btnUpdateSave" runat="server" Text="updatesave"
Icon="Disk">
<Listeners>
<Click Handler="
updateRecord(#{frmBadgeReader});
#{wndAddNew}.setVisible(false);
#{st_BadgeReaders}.load();
" />
</Listeners>
</ext:Button>
</Buttons>
</ext:FormPanel>
</Content>
</ext:Window>

Daniil
May 22, 2013, 9:57 AM
Hi John,

Please replace

grid.store.insert(0, new BadgeReader(form.getForm().getValues()));
with

grid.store.insert(0, new BadgeReader(form.getForm().getFieldValues()));

Also you should not set up Mapping for ModelFields if it coincides with its Names.

<ext:ModelField Name="IPADDRESS" Type="String" Mapping="IPADDRESS" />
<ext:ModelField Name="Enabled" Type="Boolean" Mapping="Enabled" />

John_Writers
May 22, 2013, 10:05 AM
Ok,

now it works like a charm.

Thank you for your time.

Have a good day!