<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Efficy Overflow Q&amp;A - Recent questions tagged form-validation</title>
<link>https://overflow.efficy.io/?qa=tag/form-validation</link>
<description>Powered by Question2Answer</description>
<item>
<title>field validation before submit: not a function</title>
<link>https://overflow.efficy.io/?qa=2971/field-validation-before-submit-not-a-function</link>
<description>&lt;p&gt;Hi!&lt;/p&gt;

&lt;p&gt;On the entitie Opportunity I want to validate custom fields before save/apply change in Edit form.&lt;/p&gt;

&lt;p&gt;I do it like this:&lt;br&gt;
&lt;strong&gt;FormFieldsEditCustom.txt:&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;label.CESURE {[&amp;lt;dd&amp;gt;Cesure&amp;lt;/dd&amp;gt;]}
field.CESURE {[&amp;lt;%GetEdit(&quot;$FIELD$&quot;, constraint=&quot;ComputePercent('$FIELD$')&quot;)%&amp;gt;]}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;MacroEditSCustom.txt:&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;JsScriptsTRW.Oppo {[
&amp;lt;script&amp;gt;
//Other efficy methods
    function ComputePercent(callField){
        console.log(callField);
        /**
         * callField = field name that called the function
         * values : F_CESURE1, F_CESURE2, F_CESURE3, F_CESURE4
         */

        //if value is negative --&amp;gt; err
        if(document.getElementById(callField).value&amp;lt;0){
            alert(callField+ &quot; n'admet pas de valeur négative&quot;);
            document.getElementById(callField).value = Model(callField);
            return false;
        }
        return true;
    }
&amp;lt;/script&amp;gt;]}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;MacroEditCustom.txt&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;JsonEditModelCustom.Oppo {[
    ,&quot;F_CESURE1&quot;: &quot;&amp;lt;%GetField(F_CESURE1)%&amp;gt;&quot;
    ,&quot;F_CESURE2&quot;: &quot;&amp;lt;%GetField(F_CESURE2)%&amp;gt;&quot;
    ,&quot;F_CESURE3&quot;: &quot;&amp;lt;%GetField(F_CESURE3)%&amp;gt;&quot;
    ,&quot;F_CESURE4&quot;: &quot;&amp;lt;%GetField(F_CESURE4)%&amp;gt;&quot;
]}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;In my Edit form I have 4 field (F&lt;em&gt;CESURE1, F&lt;/em&gt;CESURE2, F&lt;em&gt;CESURE3, F&lt;/em&gt;CESURE4) with the definition &quot;CESURE&quot;. When I click on &quot;save&quot; or &quot;apply&quot; button, the first field works good, but the second throw the excpetion below in the console:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Uncaught TypeError: ComputePercent(...) is not a function&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Can anyone explain me why ?&lt;br&gt;
These fields are a percentage, how can I check if their sum = 100 when I click on &quot;save&quot; or &quot;apply&quot;&lt;/p&gt;
</description>
<category>Efficy/ Client side</category>
<guid isPermaLink="true">https://overflow.efficy.io/?qa=2971/field-validation-before-submit-not-a-function</guid>
<pubDate>Mon, 12 Mar 2018 10:25:45 +0000</pubDate>
</item>
</channel>
</rss>