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

Filepicker element does not work with required or disabledif rules

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: 2.0.1, 2.1.1, 2.2
    • Fix Version/s: 2.2
    • Component/s: Files API, Forms Library
    • Labels:
    • Testing Instructions:
      Hide

      Test 1: Check filepicker validation
      1. Log in as admin
      2. Select a course
      3. Import grades (Settings -> grade -> import -> CSV file)
      4. Click upload grades (Without choosing a file)
      5. You should see validation error.
      6. Refresh the page and click "choose a file" and cancel without selecting any file
      7. Click upload grades
      8. You should see validation error.
      9. Refresh the page and click "choose a file" and select a file
      10. Click upload grades
      11. Form should be submitted.

      Test 2: Check disable if validation
      1. Log in as admin
      2. Select a course
      3. Import grades (Settings -> grade -> import -> XML file)
      4. Enter text in "Remote file URL" and then click outside
      5. "Choose a file" button should be disabled.
      6. Delete text in "Remote file URL" and then click outside
      6a. "Choose a file" button should be enabled
      7. Click "Choose a file" button and cancel
      8. Nothing should happen
      9. Click "Choose a file" button and select a file
      10. "Remote file URL" should be disabled.
      11. Try submit the form and form should be submitted.

      Test 3:
      1. copy attached test.php in moodle installation
      2. Login as admin
      3. access test.php
      4. In "Filepicker serverside validation test" click "choose a file" but don't upload and click "server validation"
      5. You should see validation error in red and url should be changed, adding sesskey and other variables
      6. Now add a file and click "server validation"
      7. On top of page it should say "test passed"
      8. Repeat 5-7 for "Filepicker clientside validation test" and it should work similar to serverside validation.
      Note: There is no client side validation happening, this test make sure that if client or server side is set then validation should happen on serverside for filepicker.
      9. In "Filepicker disableif validation test", enter text and click outside.
      10. Filepicker button should be disabled
      11. Clear text and select a file, make sure text field is disabled
      12. Clicking on validation button should show "test passed"
      13. Repeat 5-8 for "Filemanager server/client side validation test" and it should behave similarly.
      Note;
      Make sure to add files from server area, recent file area, upload a file and private area of filepicker and filemanager to make sure file is picked from all the places.

      Show
      Test 1: Check filepicker validation 1. Log in as admin 2. Select a course 3. Import grades (Settings -> grade -> import -> CSV file) 4. Click upload grades (Without choosing a file) 5. You should see validation error. 6. Refresh the page and click "choose a file" and cancel without selecting any file 7. Click upload grades 8. You should see validation error. 9. Refresh the page and click "choose a file" and select a file 10. Click upload grades 11. Form should be submitted. Test 2: Check disable if validation 1. Log in as admin 2. Select a course 3. Import grades (Settings -> grade -> import -> XML file) 4. Enter text in "Remote file URL" and then click outside 5. "Choose a file" button should be disabled. 6. Delete text in "Remote file URL" and then click outside 6a. "Choose a file" button should be enabled 7. Click "Choose a file" button and cancel 8. Nothing should happen 9. Click "Choose a file" button and select a file 10. "Remote file URL" should be disabled. 11. Try submit the form and form should be submitted. Test 3: 1. copy attached test.php in moodle installation 2. Login as admin 3. access test.php 4. In "Filepicker serverside validation test" click "choose a file" but don't upload and click "server validation" 5. You should see validation error in red and url should be changed, adding sesskey and other variables 6. Now add a file and click "server validation" 7. On top of page it should say "test passed" 8. Repeat 5-7 for "Filepicker clientside validation test" and it should work similar to serverside validation. Note: There is no client side validation happening, this test make sure that if client or server side is set then validation should happen on serverside for filepicker. 9. In "Filepicker disableif validation test", enter text and click outside. 10. Filepicker button should be disabled 11. Clear text and select a file, make sure text field is disabled 12. Clicking on validation button should show "test passed" 13. Repeat 5-8 for "Filemanager server/client side validation test" and it should behave similarly. Note; Make sure to add files from server area, recent file area, upload a file and private area of filepicker and filemanager to make sure file is picked from all the places.
    • Affected Branches:
      MOODLE_20_STABLE, MOODLE_21_STABLE, MOODLE_22_STABLE
    • Fixed Branches:
      MOODLE_22_STABLE
    • Pull Master Branch:
      wip-mdl-25937-disableif

      Description

      While peer-reviewing a patch I stumbled upon a bug with the file picker / mforms library.
      I was on a form where I was required to upload a file, however I found I could submit the form and proceed without the file.
      Originally I thought someone had forgot to add a required rule, however upon inspecting the form I see that it does indeed have a required rule on the file picker element.

      To reproduce:

      1. Log in as an admin
      2. Enter a course and click grades in the settings block for that course.
      3. In the settings block again under Grade administration expand Import and click CSV file
      4. On the form you see immediately click Upload grades

      Outcome: You will be taken to the next form in the series, however because the file picker has a required rule I would expect to get an error and see the original form again.
      I tested this by adding a validate method and manually validating the field, doing this worked fine, however it isn't a fix its a work around.

      Yell out if there is anything more I can help with.

      Cheers
      Sam

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

                People

                • Votes:
                  1 Vote for this issue
                  Watchers:
                  8 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Fix Release Date:
                    5/Dec/11