Is there anyway to prevent the isUnique validator from returning true when editing an existing record with the field that is set isUnique and saving (updating) the changes? I'd like to use isUnique and be able to update a record with the same name, but prevent the update from overwriting another name (keep enforcing the uniqueness).
I'm running SmartGWT Power 2.3 on Firefox 3.6 with an Oracle 10g database.
I've attached a picture (ping.png) of what I'm seeing and here is code to reproduce this situation.
Here is the db schema:
Here is the ds.xml:
Here is test driver:
Steps to reproduce this issue:
Create a new record and save. Select the record from the ListGrid to edit it. Change the 'Other' data and save. The "isUnique" validator will trigger and prevent the record from being saved even though I am updating the same record.
I would expect isUnique not to be triggered if the record primary key matched the record I was trying to update and the isUnique field, name in this case, was identical.
I'm running SmartGWT Power 2.3 on Firefox 3.6 with an Oracle 10g database.
I've attached a picture (ping.png) of what I'm seeing and here is code to reproduce this situation.
Here is the db schema:
Code:
DROP TABLE Ping; CREATE TABLE Ping ( id number(10) not null, name varchar2(51) unique not null, other varchar2(21), CONSTRAINT PK_PING primary key(id) ); drop sequence ping_seq; create sequence ping_seq start with 1 increment by 1 nocache;
Code:
<DataSource schema="PING" dbName="Oracle" tableName="PING" ID="PING" serverType="sql" serverConstructor="com.smartgwt.sample.server.datasource.Ping" > <fields> <field sequenceName="PING_SEQ" primaryKey="true" name="id" type="sequence" hidden="true"></field> <field name="name" length="51" type="text"> <validators> <validator type="isUnique" requiresServer="true" /> </validators> </field> <field name="other" length="21" type="text"></field> </fields> <operationBindings> <operationBinding operationType="add"></operationBinding> <operationBinding operationType="update"></operationBinding> <operationBinding operationType="remove"></operationBinding> <operationBinding operationType="fetch"></operationBinding> </operationBindings> </DataSource>
Code:
package com.smartgwt.sample.client; import com.google.gwt.core.client.EntryPoint; import com.smartgwt.client.data.DataSource; import com.smartgwt.client.data.Record; import com.smartgwt.client.widgets.Canvas; import com.smartgwt.client.widgets.IButton; import com.smartgwt.client.widgets.events.ClickEvent; import com.smartgwt.client.widgets.events.ClickHandler; import com.smartgwt.client.widgets.form.DynamicForm; import com.smartgwt.client.widgets.grid.ListGrid; import com.smartgwt.client.widgets.grid.events.RecordClickEvent; import com.smartgwt.client.widgets.grid.events.RecordClickHandler; import com.smartgwt.client.widgets.layout.HLayout; import com.smartgwt.client.widgets.layout.VStack; public class Ping implements EntryPoint { private ListGrid grid; private DynamicForm form; private IButton saveBtn; private IButton newBtn; public void onModuleLoad() { Canvas mainCanvas = new Canvas(); mainCanvas.setHeight100(); mainCanvas.setWidth100(); mainCanvas.setBackgroundColor("green"); DataSource ds = DataSource.get("PING"); VStack vstack = new VStack(); vstack.setLeft(10); vstack.setTop(10); vstack.setWidth("80%"); vstack.setHeight("80%"); vstack.setMembersMargin(10); grid = new ListGrid(); grid.setDataSource(ds); grid.setWidth(300); grid.setHeight(200); grid.fetchData(); grid.addRecordClickHandler(new RecordClickHandler() { public void onRecordClick(RecordClickEvent event) { Record record = event.getRecord(); form.editRecord(record); form.enable(); saveBtn.enable(); newBtn.disable(); } }); vstack.addMember(grid); form = new DynamicForm(); form.setDataSource(ds); form.setNumCols(2); form.setAutoFocus(false); form.disable(); vstack.addMember(form); HLayout hLayout = new HLayout(10); hLayout.setMembersMargin(10); hLayout.setHeight(22); saveBtn = new IButton("Save"); saveBtn.disable(); saveBtn.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { form.saveData(); if (!form.hasErrors()) { saveBtn.disable(); } else { form.clearValues(); } } }); hLayout.addMember(saveBtn); newBtn = new IButton("New"); newBtn.enable(); newBtn.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { form.enable(); form.editNewRecord(); saveBtn.enable(); newBtn.disable(); } }); hLayout.addMember(newBtn); IButton clearBtn = new IButton("Clear"); clearBtn.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { form.disable(); form.clearValues(); saveBtn.disable(); newBtn.enable(); } }); hLayout.addMember(clearBtn); vstack.addMember(hLayout); mainCanvas.addChild(vstack); mainCanvas.draw(); } }
Create a new record and save. Select the record from the ListGrid to edit it. Change the 'Other' data and save. The "isUnique" validator will trigger and prevent the record from being saved even though I am updating the same record.
I would expect isUnique not to be triggered if the record primary key matched the record I was trying to update and the isUnique field, name in this case, was identical.
Comment