Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-40132

Using compare rule results in fatal error in getValidationScript function

XMLWordPrintable

    • MOODLE_24_STABLE
    • MOODLE_31_STABLE, MOODLE_32_STABLE
    • Hide

      Simple regression test:

      1. Go to the add user form
      2. VERIFY: that you can't submit the form (client side validation kicks in) before you fill out required fields (e.g. email address

      Detailed fix test:
      1. Copy 2 attached files "my_client.php" and "myForm_client.php" to directory "moodledir/local/my/".
      2. Launch file "my_client.php".
      Without fix, this code will perform an error "Fatal error: Call to a member function on a non-object...".
      With fix, you will see a form with several fields, for testing rules

      Test “visible AND visible”.
      1) Enter number in the field(“Visible_01_01”) - “5”.
      2) Then go to next field (“Visible_01_02”) and enter number greater than 5.
      3) Then go to next field.
      4) Make sure, you see an error message "visible_02 > visible_01".
      Test “visible AND invisible”.
      1) Enter number in the field(“Visible_02”) - “2”.
      2) Then go to next field.
      3) Make sure, you see an error message "invisible > visible".
      Test “invisible AND visible”.
      1) Enter number in the field(“Visible_03”) - “7”.
      2) Then go to next field.
      3) Make sure, you see an error message "visible > invisible".
      Test “maxlength”.
      1) Enter text in the field(“Enter text 1”) - “!n@#t*t1”.
      2) Then go to next field.
      3) Make sure, you see an error message "maxlength = 4".
      Test “minlength”.
      1) Enter text in the field(“Enter text 2”) - “E1$”.
      2) Then go to next field.
      3) Make sure you see an error message "minlength = 4".
      Test “length more than 5 characters”.
      1) Enter text in the field(“Enter text 3”) - “Entertext3”.
      2) Then go to next field.
      3) Make sure you see an error message "length in range [3,5]".
      Test “length less than 3 characters”.
      1) Enter text in the field(“Enter text 3”) - “En”.
      2) Then go to next field.
      3) Make sure you see an error message "length in range [3,5]" below the field.
      Test “Email format”.
      1) Enter text in the field(“Enter E-mail”) - “mo@odle”.
      2) Then go to next field.
      3) Make sure you see an error message "need email" below the field.
      Test “Validation of regex”.
      1) Enter text in field(“Enter text 4”) - “moodle”.
      2) Then go to next field.
      3) Make sure you see an error message "need ^a[123]*z".
      Test “Lettersonly”.
      1) Enter text in field(“Enter text 5”) - “Entertext5”.
      2) Then go to next field.
      3) Make sure you see an error message “only letters”.
      Test “Alphanumeric”.
      1) Enter text in field(“Enter text 6”) - “Ent@er#6”.
      2) Then go to next field.
      3) Make sure you see an error message “only digits or letters”.
      Test “Numberic”.
      1) Enter text in field(“Enter number”) - “Ent12er”.
      2) Then go to other field.
      3) Make sure you see an error message “only digits”.

      Show
      Simple regression test: Go to the add user form VERIFY: that you can't submit the form (client side validation kicks in) before you fill out required fields (e.g. email address Detailed fix test: 1. Copy 2 attached files "my_client.php" and "myForm_client.php" to directory "moodledir/local/my/". 2. Launch file "my_client.php". Without fix, this code will perform an error "Fatal error: Call to a member function on a non-object...". With fix, you will see a form with several fields, for testing rules Test “visible AND visible”. 1) Enter number in the field(“Visible_01_01”) - “5”. 2) Then go to next field (“Visible_01_02”) and enter number greater than 5. 3) Then go to next field. 4) Make sure, you see an error message "visible_02 > visible_01". Test “visible AND invisible”. 1) Enter number in the field(“Visible_02”) - “2”. 2) Then go to next field. 3) Make sure, you see an error message "invisible > visible". Test “invisible AND visible”. 1) Enter number in the field(“Visible_03”) - “7”. 2) Then go to next field. 3) Make sure, you see an error message "visible > invisible". Test “maxlength”. 1) Enter text in the field(“Enter text 1”) - “!n@#t*t1”. 2) Then go to next field. 3) Make sure, you see an error message "maxlength = 4". Test “minlength”. 1) Enter text in the field(“Enter text 2”) - “E1$”. 2) Then go to next field. 3) Make sure you see an error message "minlength = 4". Test “length more than 5 characters”. 1) Enter text in the field(“Enter text 3”) - “Entertext3”. 2) Then go to next field. 3) Make sure you see an error message "length in range [3,5] ". Test “length less than 3 characters”. 1) Enter text in the field(“Enter text 3”) - “En”. 2) Then go to next field. 3) Make sure you see an error message "length in range [3,5] " below the field. Test “Email format”. 1) Enter text in the field(“Enter E-mail”) - “mo@odle”. 2) Then go to next field. 3) Make sure you see an error message "need email" below the field. Test “Validation of regex”. 1) Enter text in field(“Enter text 4”) - “moodle”. 2) Then go to next field. 3) Make sure you see an error message "need ^a [123] *z". Test “Lettersonly”. 1) Enter text in field(“Enter text 5”) - “Entertext5”. 2) Then go to next field. 3) Make sure you see an error message “only letters”. Test “Alphanumeric”. 1) Enter text in field(“Enter text 6”) - “Ent@er#6”. 2) Then go to next field. 3) Make sure you see an error message “only digits or letters”. Test “Numberic”. 1) Enter text in field(“Enter number”) - “Ent12er”. 2) Then go to other field. 3) Make sure you see an error message “only digits”.

      Easiest way to reproduce this bug is adding this code to any moodle form:

      $mform->addElement('text','name1','3',array('size'=>3));
      $mform->addElement('hidden', 'name2', '5');
      $mform->addRule(array('name1', 'name2'),'You can\'t delete blanks','compare','>=','client',true);//this line results in error in getValidationScript
      

      Last line in Moodle 2.4 gives you

      "Fatal error: Call to a member function getType() on a non-object in Z:\home\moodle\www\lib\formslib.php on line 1818"
      

      I don't have a Moodle 2.5 instance where I could run code for now, but I doubt this was fixed in formslib

        1. my_client_other.php
          0.4 kB
        2. my_client.php
          0.4 kB
        3. my_client.php
          0.4 kB
        4. my.php
          0.4 kB
        5. myForm_client_other.php
          2 kB
        6. myForm_client.php
          4 kB
        7. myForm_client.php
          2 kB
        8. myForm.php
          2 kB

            Unassigned Unassigned
            oa_sychev Oleg Sychev
            David Monllaó David Monllaó
            Dan Poltawski Dan Poltawski
            Ankit Agarwal Ankit Agarwal
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.