<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Agence de Développement Informatique du Nord &#187; javascript</title>
	<atom:link href="http://blog.adin.pro/tag/javascript-2/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.adin.pro</link>
	<description>Just another WordPress site</description>
	<lastBuildDate>Thu, 26 Dec 2019 08:54:31 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=4.1.1</generator>
	<item>
		<title>Magento multi fields validator for RIB</title>
		<link>http://blog.adin.pro/2014-02-28/magento-multi-fields-validator-for-rib/</link>
		<comments>http://blog.adin.pro/2014-02-28/magento-multi-fields-validator-for-rib/#comments</comments>
		<pubDate>Fri, 28 Feb 2014 08:56:34 +0000</pubDate>
		<dc:creator><![CDATA[blogadmin]]></dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[magento]]></category>
		<category><![CDATA[RIB]]></category>
		<category><![CDATA[validator]]></category>
		<category><![CDATA[VarienForm]]></category>

		<guid isPermaLink="false">http://blog.adin.pro/?p=360</guid>
		<description><![CDATA[<p>Magento come with a great form validator : VarienForm. These is a lot of existing validator, for every usage and you can easyly add some. This is how you can do it with a commun example, how to check RIB &#8230; <a href="http://blog.adin.pro/2014-02-28/magento-multi-fields-validator-for-rib/">Continue reading <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2014-02-28/magento-multi-fields-validator-for-rib/">Magento multi fields validator for RIB</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>Magento come with a great form validator : VarienForm. These is a lot of existing validator, for every usage and you can easyly add some. This is how you can do it with a commun example, how to check RIB bank account.</p>
<p>First, our html code</p>
<pre class="brush: xml; title: ; notranslate">
&lt;ul class=&quot;inlineblockli&quot;&gt;
	&lt;li&gt;
		&lt;label for=&quot;code_bank_pb&quot;&gt;&lt;?php echo $this-&gt;__('bank code') ?&gt;&lt;/label&gt;
                &lt;input type=&quot;text&quot; class=&quot;inputText inputTextB validate-digits required-entry validate-length minimum-length-5 maximum-length-5&quot; id=&quot;code_bank_pb&quot; maxlength=&quot;5&quot; name=&quot;prelevement[code_bank_pb]&quot;&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;label for=&quot;code_guichet_pb&quot;&gt;&lt;?php echo $this-&gt;__('branch code') ?&gt;&lt;/label&gt;
                &lt;input type=&quot;text&quot; class=&quot;inputText inputTextB validate-digits required-entry validate-length minimum-length-5 maximum-length-5&quot; id=&quot;code_guichet_pb&quot; maxlength=&quot;5&quot; name=&quot;prelevement[code_guichet_pb]&quot;&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;label for=&quot;num_compte&quot;&gt;&lt;?php echo $this-&gt;__('Account number to be debited') ?&gt;&lt;/label&gt;
                &lt;input type=&quot;text&quot; class=&quot;inputText inputTextBig3 validate-digits required-entry validate-length minimum-length-11 maximum-length-11&quot; id=&quot;num_compte&quot; maxlength=&quot;11&quot; name=&quot;prelevement[num_compte]&quot;&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;label for=&quot;key_rib&quot;&gt;&lt;?php echo $this-&gt;__('RIB key') ?&gt;&lt;/label&gt;
                &lt;input type=&quot;text&quot; class=&quot;inputText inputTextSm3 validate-digits required-entry validate-compte validate-length minimum-length-2 maximum-length-2&quot; id=&quot;key_rib&quot; maxlength=&quot;2&quot; name=&quot;prelevement[key_rib]&quot;&gt;
	&lt;/li&gt;
&lt;/ul&gt;
</pre>
<p>We first do a lenght validation with these 3 class : validate-length minimum-length-11 maximum-length-11</p>
<p>Then we validate the rib with this class : validate-compte<br />
You will tell me this validator doesn&#8217;t exeist. That&#8217;s right, let&#8217;s create it.</p>
<pre class="brush: jscript; title: ; notranslate">
&lt;script type=&quot;text/javascript&quot;&gt;
    //&lt;![CDATA[
    Validation.addAllThese(
        [
            ['validate-compte', '&lt;?php echo Mage::helper('rating')-&gt;__('Please check your RIB account') ?&gt;', function(v) {
                var code_banque = jQuery('#code_bank_pb').val();
                var code_guichet = jQuery('#code_guichet_pb').val();
                var numero_compte = jQuery('#num_compte').val();
                var cle           = jQuery('#key_rib').val();

                var CompteTmp = code_banque + code_guichet + numero_compte + cle;

                while(CompteTmp.length &gt; 9)
                {
                    var CompteTmp2 = CompteTmp.substr(0,9) % 97;
                    CompteTmp = CompteTmp2 + CompteTmp.substr(9,CompteTmp.length);
                }
                var CompteTmp2 = CompteTmp.substr(0,9) % 97;

                if(CompteTmp2 % 97 == 0)
                {
                    return true;
                }
                return false;
            }]
        ]
    );
    //]]&gt;
&lt;/script&gt;
</pre>
<p>Some explainations :</p>
<pre class="brush: jscript; title: ; notranslate">
jQuery('#code_bank_pb').val();
</pre>
<p>Magento use prototype, tu use jQuery, use jQuery instead of $</p>
<p>For the multi field validation, I grab the different fields from this</p>
<pre class="brush: jscript; title: ; notranslate">
var code_banque   = jQuery('#code_bank_pb').val();
var code_guichet  = jQuery('#code_guichet_pb').val();
var numero_compte = jQuery('#num_compte').val();
var cle           = jQuery('#key_rib').val();
</pre>
<p>I don&#8217;t know if this is the cleaner way to do (not really usable for another code) but it works.<br />
If you always use the same input id, you can reuse this code on another site.</p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2014-02-28/magento-multi-fields-validator-for-rib/">Magento multi fields validator for RIB</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adin.pro/2014-02-28/magento-multi-fields-validator-for-rib/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
