Skip to content

Commit

Permalink
MDL-83713 form: Fix javascript selector on file picker
Browse files Browse the repository at this point in the history
  • Loading branch information
jboulen committed Nov 25, 2024
1 parent 505a85e commit fa6071e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
29 changes: 29 additions & 0 deletions grade/import/xml/tests/behat/import.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
@gradeimport @gradeimport_xml @javascript @_file_upload
Feature: A teacher can import grades with a XML file or with an URL
In order to import grades using a XML file
As a teacher
I need to be able to upload a local XML file or to give a remote file URL

Background:
Given the following "courses" exist:
| fullname | shortname | format |
| Course 1 | C1 | topics |
And the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |

Scenario: The remote file URL field is disabled when the file picker is not empty
Given I am on the "Course 1" "Course" page logged in as "teacher1"
And I navigate to "XML file" import page in the course gradebook
And I upload "lib/ddl/tests/fixtures/xmldb_table.xml" file to "File" filemanager
Then the "disabled" attribute of "input#id_url" "css_element" should contain "true"

Scenario: The file picker is disabled when the remote file URL field is not empty
Given I am on the "Course 1" "Course" page logged in as "teacher1"
And I navigate to "XML file" import page in the course gradebook
And I set the following fields to these values:
| Remote file URL | https://example.com/grades.xml |
Then the "disabled" attribute of "input#id_userfile" "css_element" should contain "true"
12 changes: 6 additions & 6 deletions lib/form/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -485,8 +485,8 @@ if (typeof M.form.dependencyManager === 'undefined') {
}
if (this.getAttribute('class').toLowerCase() == 'filepickerhidden') {
// Check for filepicker status.
var elementname = this.getAttribute('name');
if (elementname && M.form_filepicker.instances[elementname].fileadded) {
var elementid = this.getAttribute('id');
if (elementid && M.form_filepicker.instances[elementid].fileadded) {
lock = false;
} else {
lock = true;
Expand Down Expand Up @@ -553,8 +553,8 @@ if (typeof M.form.dependencyManager === 'undefined') {
}
if (this.getAttribute('class').toLowerCase() == 'filepickerhidden') {
// Check for filepicker status.
var elementname = this.getAttribute('name');
if (elementname && M.form_filepicker.instances[elementname].fileadded) {
var elementid = this.getAttribute('id');
if (elementid && M.form_filepicker.instances[elementid].fileadded) {
lock = false;
} else {
lock = true;
Expand Down Expand Up @@ -617,8 +617,8 @@ if (typeof M.form.dependencyManager === 'undefined') {
}
// Check for filepicker status.
if (this.getAttribute('class').toLowerCase() == 'filepickerhidden') {
var elementname = this.getAttribute('name');
if (elementname && M.form_filepicker.instances[elementname].fileadded) {
var elementid = this.getAttribute('id');
if (elementid && M.form_filepicker.instances[elementid].fileadded) {
lock = true;
} else {
lock = false;
Expand Down

0 comments on commit fa6071e

Please sign in to comment.