-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: course id fields restriction & js uncaught element bug fixed (#46)
* feat: course id fields restriction & js bug fixed * refactor: whitespace error fixed
- Loading branch information
1 parent
eedf105
commit 9551c99
Showing
4 changed files
with
59 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
var originalValue = ""; | ||
|
||
|
||
var inputElementForm = document.getElementById("openedx_enrollment_course_id"); | ||
var inputElementProduct = document.getElementById("_course_id"); | ||
var inputElement = null; | ||
|
||
if (inputElementForm !== null) { | ||
inputElement = inputElementForm; | ||
} else if (inputElementProduct !== null) { | ||
inputElement = inputElementProduct; | ||
} | ||
|
||
if (inputElement !== null) { | ||
|
||
inputElement.addEventListener("input", function() { | ||
updateCourseId(this); | ||
}); | ||
|
||
|
||
inputElement.addEventListener("focus", function() { | ||
saveOriginalValue(this); | ||
}); | ||
|
||
|
||
inputElement.addEventListener("blur", function() { | ||
restoreOriginalValue(this); | ||
}); | ||
|
||
function saveOriginalValue(input) { | ||
originalValue = input.value; | ||
} | ||
|
||
function restoreOriginalValue(input) { | ||
if (input.value !== originalValue && !input.value.startsWith("course-v1:")) { | ||
input.value = originalValue; | ||
} | ||
} | ||
|
||
function updateCourseId(input) { | ||
var prefix = "course-v1:"; | ||
var currentValue = input.value; | ||
|
||
if (currentValue !== "" && !currentValue.startsWith(prefix)) { | ||
input.value = prefix; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters