diff options
| author | Moritz Strohm <strohm@data-quest.de> | 2025-01-10 13:34:43 +0000 |
|---|---|---|
| committer | Moritz Strohm <strohm@data-quest.de> | 2025-01-10 13:34:43 +0000 |
| commit | 0197b62000071439ef6f72d7a4972fefbaf1acac (patch) | |
| tree | bd1b820478f3869ed4dcd499458f5fc383d171d2 /resources/assets/javascripts/bootstrap | |
| parent | 39745c9aa8bb099e8bda1f4d775ed229dbe97be4 (diff) | |
StEP 3348, closes #3348
Closes #3348
Merge request studip/studip!2275
Diffstat (limited to 'resources/assets/javascripts/bootstrap')
| -rw-r--r-- | resources/assets/javascripts/bootstrap/studip_helper_attributes.js | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/resources/assets/javascripts/bootstrap/studip_helper_attributes.js b/resources/assets/javascripts/bootstrap/studip_helper_attributes.js index 26cdd9c..54f8da3 100644 --- a/resources/assets/javascripts/bootstrap/studip_helper_attributes.js +++ b/resources/assets/javascripts/bootstrap/studip_helper_attributes.js @@ -133,7 +133,7 @@ STUDIP.ready((event) => { // $(document).on('change', '[data-hides],[data-shows]', function () { - if (!$(this).is(':checkbox,:radio')) { + if (!$(this).is(':checkbox,:radio,select')) { return; } @@ -142,14 +142,40 @@ $(document).on('change', '[data-hides],[data-shows]', function () { if (selector === undefined || $(this).prop('disabled')) { return; } - - var state = $(this).prop('checked') || $(this).prop('indeterminate') || false; + let triggering_value = undefined; + if ($(this).is('select')) { + triggering_value = $(this).data('triggering-value').toString(); + } + let state = $(this).prop('checked') || $(this).prop('indeterminate') || $(this).val().toString() === triggering_value || false; $(selector).each(function() { var condition = $(this).data(`${type}Condition`), toggle = state && (!condition || $(condition).length > 0); $(this) .toggle(type === 'shows' ? toggle : !toggle) .trigger('update.proxy'); + //Check if there are required fields that become hidden or the other way around. + //Hidden fields must not be required. + let elements = $(this).find('input[required]'); + if ($(this).attr('required')) { + //Append the element itself: + $(elements).append($(this)); + } + $(elements).each(function(index, element) { + + let hide = (type === 'shows' && !condition) || (type === 'hides' && condition); + if (hide) { + //Remove the required attribute: + if ($(element).attr('required') !== 'false') { + $(element).attr('data-is_required', '1'); + $(element).removeAttr('required'); + } + } else { + //Set the required attribute: + if ($(element).attr('data-is_required')) { + $(element).attr('required', 'required'); + } + } + }); }); }); }); |
