Skip to content

Commit

Permalink
Add a 'required' attribute to the rep_interval field
Browse files Browse the repository at this point in the history
  • Loading branch information
campbell-m committed Aug 10, 2023
1 parent 3fd52a6 commit 4ee74d9
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions web/js/edit_entry.js.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,19 @@


<?php
// Function to display the secondary repeat type fieldset appropriate
// to the selected repeat type
// Function to (1) add a 'required' attribute to the rep_interval field if it's a repeating booking
// and (2) to display the secondary repeat type fieldset appropriate to the selected repeat type.
?>
var changeRepTypeDetails = function changeRepTypeDetails() {
var repType = parseInt($('input[name="rep_type"]:checked').val(), 10);
<?php
// Add a 'required' attribute to the rep_interval input to prevent users entering an
// empty string. But remove it if it's not a repeating entry, because if they happen
// to have an empty string they won't see the validation message because the input
// will be hidden.
?>
$('#rep_interval').prop('required', (repType !== <?php echo RepeatRule::NONE ?>));
<?php // Show the appropriate details ?>
$('.rep_type_details').hide();
switch (repType)
{
Expand Down Expand Up @@ -1644,11 +1652,12 @@ function populateFromSessionStorage(form)
checkTimeSlots($(this));
});

$('input[name="rep_type"]').on('change', changeRepTypeDetails);
changeRepTypeDetails();

$('input[name="rep_interval"]').on('change', changeRepIntervalUnits);
$('input[name="rep_type"]').on('change', changeRepIntervalUnits).trigger('change');

$('input[name="rep_type"]').on('change', function() {
changeRepTypeDetails();
changeRepIntervalUnits();
}).trigger('change');

<?php
// Add an event listener to detect a change in the visibility
Expand Down

0 comments on commit 4ee74d9

Please sign in to comment.