<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
	<title>jQuery Grid Plugin - jqGrid - Topic: how to use custom_func in editrules for server side sync validation</title>
	<link>http://www.trirand.com/blog/?page_id=393/help/how-to-use-custom_func-in-editrules-for-server-side-sync-validation</link>
	<description><![CDATA[Grid plugin]]></description>
	<generator>Simple:Press Version 5.7.5.3</generator>
	<atom:link href="http://www.trirand.com/blog/?page_id=393/help/how-to-use-custom_func-in-editrules-for-server-side-sync-validation/rss" rel="self" type="application/rss+xml" />
        <item>
        	<title>kobruleht on how to use custom_func in editrules for server side sync validation</title>
        	<link>http://www.trirand.com/blog/?page_id=393/help/how-to-use-custom_func-in-editrules-for-server-side-sync-validation#p23927</link>
        	<category>Help</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/help/how-to-use-custom_func-in-editrules-for-server-side-sync-validation#p23927</guid>
        	        	<description><![CDATA[<p>Oleg,</p>
</p>
<p>thank you. Server side validation in my application works exactly as you described.&#160; However I&#39;m trying to implement a bit different usage case&#160;like this:</p>
<p>If user enters product code, server should validate this code.&#160; If code is ok, server returns product name, customer discount, price, quantity in stock and ordered quantity.</p>
<p>From your reply I understand that you recommend to do all this after row is saved and overwrite row data after save. There are issues with this:</p>
<p>1.&#160;Users can enter foreign key values or foreigh key fields, e.q</p>
<p>If product code is entered, server should return product name and other data. If product name is entered, server should show and update product code. Issue: On save&#160;save server does not know which foregin key column (id or name) was filled by user and which column need to be calculated.</p>
<p>For product there can entered product code, product id, barcode, product name, serial number. If one is entered, server shoudl update other columns in order automatically and preferably immediately.</p>
</p>
<p>2. Pertial save&#160;is inconvenient: to get name/product id, quantity on stocks, price, ordered&#160;quantity,row should partially saved.&#160;After that row should re-opened&#160;quantity to order should entered or row shoudl be edited or deleted.</p>
<p>3. Row data needs overwritten also if save was OK.</p>
</p>
<p>I don&#39;t know how to fix those using your recommendation. So I&#39;m looking for a way to return those data after product id or name or other foreign key is entered.</p>
<p>I tried</p>
<p><input type='button' class='sfcodeselect' name='sfselectit3102' value='Select Code' data-codeid='sfcode3102' /></p>
<div class='sfcode' id='sfcode3102'>
<p>colModel: [{&#34;label&#34;:&#34;ProductCode&#34;,&#34;name&#34;:&#34;ProductCode&#34;,&#34;editoptions&#34;:{<br />&#34;dataEvents&#34;:[<br />{&#34;type&#34;:&#34;focus&#34;,&#34;fn&#34;:function(e) { ischanged=false}},<br />{&#34;type&#34;:&#34;change&#34;,&#34;fn&#34;:function(e) {ischanged=true}},<br />{&#34;type&#34;:&#34;keydown&#34;,&#34;fn&#34;:function(e) {ischanged=true }},<br />{&#34;type&#34;:&#34;blur&#34;,&#34;fn&#34;:function(e) { if(ischanged) validate(e)} }<br />]},</p>
</div>
<p>To implement validate I found code from your great answer in Stack Overflow (I upvoted answer):</p>
<p><input type='button' class='sfcodeselect' name='sfselectit3879' value='Select Code' data-codeid='sfcode3879' /></p>
<div class='sfcode' id='sfcode3879'>
<p>function validate(e) {</p>
<p>var elem = e.target;<br />ischanged = false;<br />$.ajax( &#39;/validate&#39;,{<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; data: ({ value: $(elem).val() }), // todo: how to pass all row data<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; async: false,<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; success: function (data, textStatus, jqXHR) {</p>
<p>&#160;&#160;&#160; // todo: how to overwrite all rows with server data<br />&#160;&#160;&#160; if ($(e.target).is(&#39;.FormElement&#39;)) {<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; // form editing<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; var form = $(e.target).closest(&#39;form.FormGrid&#39;);<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; $(&#39;#ProductName.FormElement&#39;,form[0]).val(data.value);<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; } else {<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; // inline editing<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; var row = $(e.target).closest(&#39;tr.jqgrow&#39;);<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; var rowId = row.attr(&#39;id&#39;);<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; $(&#39;#&#39;+rowId+&#39;_ProductName&#39;).val(data.value);<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }<br />&#160;&#160; }}</p>
</div>
<p>Is this best way to solve the issue? However, this passes and overwrites only single column. How to pass whole row to server and overwrite whole row with values returned form server? For overwriting all rows with data returned from server I think I can return server array which contains column name and column value. In this case this code can modified to write changed data to all columns. IS this best way? For me difficult part is to pass all columns to server. How to implement this ? Has jqGrid some function or how to loop over all columns and send those values to server ?</p>
]]></description>
        	        	<pubDate>Sun, 10 Jul 2011 21:16:24 +0300</pubDate>
        </item>
        <item>
        	<title>OlegK on how to use custom_func in editrules for server side sync validation</title>
        	<link>http://www.trirand.com/blog/?page_id=393/help/how-to-use-custom_func-in-editrules-for-server-side-sync-validation#p23925</link>
        	<category>Help</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/help/how-to-use-custom_func-in-editrules-for-server-side-sync-validation#p23925</guid>
        	        	<description><![CDATA[<p>It you just try to save the modification the server should valudate the data before ot save in in the database. If the validateion failed the server should answer with the <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4" target="_blank">error HTTP code</a>. In the case you can impelemnt the reloading of the data inside of the <em>errorfunc</em> of the <strong>editRow</strong> or the event handler <em>errorTextFormat</em> of the <strong>editGridRow</strong>. If the error message which you display is clear enough the user can reload the grid herself.</p>
<p>So im my opinion the server side validation of the data is the part of saving the data. If the server validation are implemented is the CHECK CONSTRAINT of the database or inside of the code of your STORED PROCEDUREs the SQL exception will be thorwn and you will have almost the same validation errors like I described before.</p>
<p>Best regards<br />Oleg&#160;</p>
]]></description>
        	        	<pubDate>Sun, 10 Jul 2011 13:32:38 +0300</pubDate>
        </item>
        <item>
        	<title>kobruleht on how to use custom_func in editrules for server side sync validation</title>
        	<link>http://www.trirand.com/blog/?page_id=393/help/how-to-use-custom_func-in-editrules-for-server-side-sync-validation#p23921</link>
        	<category>Help</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/help/how-to-use-custom_func-in-editrules-for-server-side-sync-validation#p23921</guid>
        	        	<description><![CDATA[<p>I&#39;m looking for a way to perform field validation in server side in inline and form edit and update<br />column with result so that edit mode is not terminated.</p>
<p>I tried in colModel:</p>
<p><input type='button' class='sfcodeselect' name='sfselectit1377' value='Select Code' data-codeid='sfcode1377' /></p>
<div class='sfcode' id='sfcode1377'>
<p>editrules = { custom = true,<br />custom_func = function (value, colname) {return [false, &#39;test&#39;]}<br />}</p>
</div>
<p>it looks like that custom_func is called only if enter is pressed to save form.<br />How to call custom_func immediately if field is changed and loses focus or if field has changed and enter is pressed <br />without losing focus or is there better way to validate changed column immediately if it loses focus ?</p>
]]></description>
        	        	<pubDate>Sat, 09 Jul 2011 22:37:55 +0300</pubDate>
        </item>
</channel>
</rss>