[SOLVED] Form Javascript | js file | if else if loop doesn't work + SOLUTION

marcq

Member
Hi,

I try hard to improve my javascript skills but...

I have created a form with several tabs, in one of my tabs I've got the following elements :

Invoice sent | date element with date picker
Invoice paid | date element with date picker
First reminder | date element without date picker
Button First reminder
Second reminder | date element without date picker
Button Second reminder
Third reminder | date element without date picker
Button Third reminder

upload_2017-2-5_22-43-41.png

Basically, when the user want to send the 1st reminder he click the blue button, is routed to another form which is a prefilled email that he can change if need, when the email is sent the "1er rappel" field is populated with the actual date.

I'm running a javascript script which should do the following :

1. If "Facture expediee" and "Facture acquittee" are empty then all buttons are disabled.
2. If "Facture expediee" is filled with a date and "Facture acquittee" are empty then the blue button is enabled, 1. the orange and red buttons are disabled.
3. If "Facture expediee" is filled with a date and "Facture acquittee" is empty and the "1er rappel" date is filled then the orange button is enabled date the blue and red buttons are disabled
4. If "Facture expediee" is filled with a date and "Facture acquittee" is empty and the "1er rappel" and "@eme rappel" date are not empty then the red button is enabled and the blue and orange buttons are disabled.

I have created the following function, but the script is not working by the third step. Is something wrong with my code ?

Code:
function feDisableButtons() {

  // GET FORM REFERENCE
  var form = Fabrik.getBlock('form_59');
   
    if (form.formElements.get('gprh_fabrik_user_registration_332_repeat___date_envoi_facture_fe').getValue() != '' && form.formElements.get('gprh_fabrik_user_registration_332_repeat___date_facture_acquittee_fe').getValue() == '') {

      jQuery('#gprh_fabrik_user_registration_332_repeat___bouton_premier_fe').attr('disabled', false);
      jQuery('#gprh_fabrik_user_registration_332_repeat___bouton_second_fe').attr('disabled',true);
      jQuery('#gprh_fabrik_user_registration_332_repeat___bouton_troisieme_fe').attr('disabled',true);

    } else if (form.formElements.get('gprh_fabrik_user_registration_332_repeat___date_envoi_facture_fe').getValue() != '' && form.formElements.get('gprh_fabrik_user_registration_332_repeat___date_facture_acquittee_fe').getValue() != '') {

      jQuery('#gprh_fabrik_user_registration_332_repeat___bouton_premier_fe').attr('disabled', true);
      jQuery('#gprh_fabrik_user_registration_332_repeat___bouton_second_fe').attr('disabled',true);
      jQuery('#gprh_fabrik_user_registration_332_repeat___bouton_troisieme_fe').attr('disabled',true);

    } else if (form.formElements.get('gprh_fabrik_user_registration_332_repeat___date_envoi_facture_fe').getValue() != '' && form.formElements.get('gprh_fabrik_user_registration_332_repeat___date_facture_acquittee_fe').getValue() == '' &&  form.formElements.get('gprh_fabrik_user_registration_332_repeat___premier_rappel_fe').getValue() != '') {

      jQuery('#gprh_fabrik_user_registration_332_repeat___bouton_premier_fe').attr('disabled', true);
      jQuery('#gprh_fabrik_user_registration_332_repeat___bouton_second_fe').attr('disabled',false);
      jQuery('#gprh_fabrik_user_registration_332_repeat___bouton_troisieme_fe').attr('disabled',true);

    } else {
  }
};

Thanks, marc
 
Update :

I try among others this after having read carefully all wikis concerning javascript, but still doesn't work and there is no error reported with firebug :

Code:
function feDisableButtons() {

  // GET FORM REFERENCE
  var form = Fabrik.getBlock('form_59');
   
    if (form.formElements.get('gprh_fabrik_user_registration_332_repeat___date_envoi_facture_fe').getValue() != '' && form.formElements.get('gprh_fabrik_user_registration_332_repeat___date_facture_acquittee_fe').getValue() == '') {

      jQuery('#gprh_fabrik_user_registration_332_repeat___bouton_premier_fe').attr('disabled', false);
      jQuery('#gprh_fabrik_user_registration_332_repeat___bouton_second_fe').attr('disabled',true);
      jQuery('#gprh_fabrik_user_registration_332_repeat___bouton_troisieme_fe').attr('disabled',true);

    } else if (form.formElements.get('gprh_fabrik_user_registration_332_repeat___date_envoi_facture_fe').getValue() != '' && form.formElements.get('gprh_fabrik_user_registration_332_repeat___date_facture_acquittee_fe').getValue() != '') {

      jQuery('#gprh_fabrik_user_registration_332_repeat___bouton_premier_fe').attr('disabled', true);
      jQuery('#gprh_fabrik_user_registration_332_repeat___bouton_second_fe').attr('disabled',true);
      jQuery('#gprh_fabrik_user_registration_332_repeat___bouton_troisieme_fe').attr('disabled',true);

    } else if (form.formElements.get('gprh_fabrik_user_registration_332_repeat___date_envoi_facture_fe').getValue() != '' && form.formElements.get('gprh_fabrik_user_registration_332_repeat___date_facture_acquittee_fe').getValue() == '' &&  form.formElements.get('gprh_fabrik_user_registration_332_repeat___premier_rappel_fe').getValue() != '') {

      jQuery('#gprh_fabrik_user_registration_332_repeat___bouton_premier_fe').attr('disabled', true);
      jQuery('#gprh_fabrik_user_registration_332_repeat___bouton_second_fe').attr('disabled',false);
      jQuery('#gprh_fabrik_user_registration_332_repeat___bouton_troisieme_fe').attr('disabled',true);

    } else if (form.formElements.get('gprh_fabrik_user_registration_332_repeat___date_envoi_facture_fe').getValue() != '' && form.formElements.get('gprh_fabrik_user_registration_332_repeat___date_facture_acquittee_fe').getValue() == '' &&  form.formElements.get('gprh_fabrik_user_registration_332_repeat___premier_rappel_fe').getValue() != '' &&  form.formElements.get('gprh_fabrik_user_registration_332_repeat___deuxieme_rappel_fe').getValue() != '') {

      jQuery('#gprh_fabrik_user_registration_332_repeat___bouton_premier_fe').attr('disabled', true);
      jQuery('#gprh_fabrik_user_registration_332_repeat___bouton_second_fe').attr('disabled',true);
      jQuery('#gprh_fabrik_user_registration_332_repeat___bouton_troisieme_fe').attr('disabled',false);

    } else {
  }
};

Since the empty value of the field is NULL I also tried to do it this way and with only one case, but it also doesn't work and firebug doesn't report any error :

Code:
function feDisableButtons() {

  // GET FORM REFERENCE
  var form = Fabrik.getBlock('form_59');

    var date_envoi_facture_fe = Fabrik.getBlock('form_59').elements.get('gprh_fabrik_user_registration_332_repeat___date_envoi_facture_fe');
    var date_facture_acquittee_fe = Fabrik.getBlock('form_59').elements.get('gprh_fabrik_user_registration_332_repeat___date_envoi_facture_fe');
    var premier_rappel_fe = Fabrik.getBlock('form_59').elements.get('gprh_fabrik_user_registration_332_repeat___premier_rappel_fe');
    var second_rappel_fe = Fabrik.getBlock('form_59').elements.get('gprh_fabrik_user_registration_332_repeat___second_rappel_fe');
    var troisieme_rappel_fe = Fabrik.getBlock('form_59').elements.get('gprh_fabrik_user_registration_332_repeat___troisieme_rappel_fe');
   
  if (!date_envoi_facture_fe && !date_facture_acquittee_fe) {

      date_envoi_facture_fe.setErrorMessage('this is the message');
      date_facture_acquittee_fe.setErrorMessage('this is the message');

      premier_rappel_fe.hide();
      second_rappel_fe.hide();
      troisieme_rappel_fe.hide();
    } else {
    }
};
 
Ok thanks please see My Sites, GPRH you will find all needed info into the Notes text area. Thanks, marc
 
Update:

Function "function feDisableButtons();" is set in the Element Javascript on change and on load to the following elements :
  • gprh_fabrik_user_registration_332_repeat___date_envoi_facture_fe
  • gprh_fabrik_user_registration_332_repeat___date_facture_acquittee_fe
  • gprh_fabrik_user_registration_332_repeat___premier_rappel_fe
  • gprh_fabrik_user_registration_332_repeat___second_rappel_fe
  • gprh_fabrik_user_registration_332_repeat___troisieme_rappel_fe

tried this and it doesn't work :

JavaScript:
function feDisableButtons() {

  // GET FORM REFERENCE
  var form = Fabrik.getBlock('form_59');
   
    if (form.formElements.get('gprh_fabrik_user_registration_332_repeat___date_envoi_facture_fe').getValue() == '' || form.formElements.get('gprh_fabrik_user_registration_332_repeat___date_envoi_facture_fe').getValue() == '0000-00-00 00:00:00' && form.formElements.get('gprh_fabrik_user_registration_332_repeat___date_facture_acquittee_fe').getValue() == '' || form.formElements.get('gprh_fabrik_user_registration_332_repeat___date_facture_acquittee_fe').getValue() == '0000-00-00 00:00:00') {

      jQuery('#gprh_fabrik_user_registration_332_repeat___bouton_premier_fe').attr('disabled', true);
      jQuery('#gprh_fabrik_user_registration_332_repeat___bouton_second_fe').attr('disabled',true);
      jQuery('#gprh_fabrik_user_registration_332_repeat___bouton_troisieme_fe').attr('disabled',true);

    } else if (form.formElements.get('gprh_fabrik_user_registration_332_repeat___date_envoi_facture_fe').getValue() != '' || form.formElements.get('gprh_fabrik_user_registration_332_repeat___date_envoi_facture_fe').getValue() !== '0000-00-00 00:00:00' && form.formElements.get('gprh_fabrik_user_registration_332_repeat___date_facture_acquittee_fe').getValue() == '' || form.formElements.get('gprh_fabrik_user_registration_332_repeat___date_facture_acquittee_fe').getValue() == '0000-00-00 00:00:00' &&  form.formElements.get('gprh_fabrik_user_registration_332_repeat___premier_rappel_fe').getValue() == '' || form.formElements.get('gprh_fabrik_user_registration_332_repeat___premier_rappel_fe').getValue() == '0000-00-00 00:00:00' &&  form.formElements.get('gprh_fabrik_user_registration_332_repeat___second_rappel_fe').getValue() == '' || form.formElements.get('gprh_fabrik_user_registration_332_repeat___second_rappel_fe').getValue() == '0000-00-00 00:00:00' &&  form.formElements.get('gprh_fabrik_user_registration_332_repeat___troisieme_rappel_fe').getValue() == '' || form.formElements.get('gprh_fabrik_user_registration_332_repeat___troisieme_rappel_fe').getValue() !== '0000-00-00 00:00:00') {

      jQuery('#gprh_fabrik_user_registration_332_repeat___bouton_premier_fe').attr('disabled', false);
      jQuery('#gprh_fabrik_user_registration_332_repeat___bouton_second_fe').attr('disabled',true);
      jQuery('#gprh_fabrik_user_registration_332_repeat___bouton_troisieme_fe').attr('disabled',true);

    } else if (form.formElements.get('gprh_fabrik_user_registration_332_repeat___date_envoi_facture_fe').getValue() != '' || form.formElements.get('gprh_fabrik_user_registration_332_repeat___date_envoi_facture_fe').getValue() !== '0000-00-00 00:00:00' && form.formElements.get('gprh_fabrik_user_registration_332_repeat___date_facture_acquittee_fe').getValue() == '' || form.formElements.get('gprh_fabrik_user_registration_332_repeat___date_facture_acquittee_fe').getValue() == '0000-00-00 00:00:00' &&  form.formElements.get('gprh_fabrik_user_registration_332_repeat___premier_rappel_fe').getValue() != '' || form.formElements.get('gprh_fabrik_user_registration_332_repeat___premier_rappel_fe' &&  form.formElements.get('gprh_fabrik_user_registration_332_repeat___second_rappel_fe').getValue() == '' || form.formElements.get('gprh_fabrik_user_registration_332_repeat___second_rappel_fe').getValue() == '0000-00-00 00:00:00' &&  form.formElements.get('gprh_fabrik_user_registration_332_repeat___troisieme_rappel_fe').getValue() == '' || form.formElements.get('gprh_fabrik_user_registration_332_repeat___troisieme_rappel_fe').getValue() !== '0000-00-00 00:00:00').getValue() !== '0000-00-00 00:00:00') {

      jQuery('#gprh_fabrik_user_registration_332_repeat___bouton_premier_fe').attr('disabled', true);
      jQuery('#gprh_fabrik_user_registration_332_repeat___bouton_second_fe').attr('disabled',false);
      jQuery('#gprh_fabrik_user_registration_332_repeat___bouton_troisieme_fe').attr('disabled',true);

    } else {
  }
};

I'm stuck now and need your support. Thanks in advance, marc
 
The login you gave me doesn't work (I'm copying and pasting the username and password), and the URL you gave me yields a 404.

-- hugh
 
Hi Hugh, sorry, I have changed the passwords. I ve checked both backend and frontend usernames and passwords and they are working now. Please see My Sites - GPRH + Notes. Thanks in advance. marc
 
OK, I loaded it by just creating a normal component link by hand.

If you open dev tools in Chrome, you'll see the error on load ...

Uncaught ReferenceError: coDisableButtons is not defined
at eval (eval at runLoadEvent (element.js:2), <anonymous>:1:1)

... it looks like one or more of your elements is trying to call coDisableButtons() on load, which doesn't exist in your JS file. So that's killing the loading of everything else.

-- hugh
 
The elements trying to call it are:

gprh_fabrik_user_registration_333_repeat___date_envoi_facture_co
gprh_fabrik_user_registration_333_repeat___premier_rappel_co
gprh_fabrik_user_registration_333_repeat___deuxieme_rappel_co
gprh_fabrik_user_registration_333_repeat___troisieme_rappel_co

-- hugh
 
Thanks Hugh, I have updated the link which lead to an 404 error into My Sites - GPRH. I saw the error on load, I didn't know that the error killed the loading of other functions.

By the way, I have disabled the javascript element of the $ fields named in thread #10. No error now, but my function is still not working.
 
I can load the front end one time. As soon as I try and login, it does the "too many redirects" thing and I have to clear the cookies for your site to get it to load again.

I finally got it to work by logging in, clearing cookies then directly pasting the form's URL in.

OK, seems to work for me, on the rowid 8 form, the first button is enabled, the second two are disabled.

-- hugh
 
Thank you Hugh, but since the blue date field is already filled, the blue button should be disabled, the orange button enabled and the red button disabled too. The 3 date elements are read only. This should happen according the js file and the script, but perhaps I have made errors by coding it.
 
OK, well the script is at least running now, so you should be able to figure out where your logic is going wrong. Try wrapping parens around your paired conditions, and putting someine breaks in, make it easier to read like...

If (
(a
||
b)
&&
(c
||
d)
)


Sent from my HTC 10 using Tapatalk
 
Well, well, well, thank you for your self explanatory solution Hugh : the brackets... It work fine now, cheers, marc

Solution attached.
 

Attachments

  • JSFUNCTION.pdf
    197.1 KB · Views: 187
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top