Skip to content

Commit

Permalink
Force datepicker ids to kebab format
Browse files Browse the repository at this point in the history
  • Loading branch information
Ioannis Igoumenos committed May 17, 2022
1 parent 1e3597a commit ff60349
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/src/View/Helper/FieldHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function control(string $fieldName,
// accessibility purposes.
$coptions['class'] = 'form-control datepicker';
$coptions['placeholder'] = 'YYYY-MM-DD HH:MM:SS'; // TODO: test for date-only inputs and send only the date
$coptions['id'] = $fieldName;
$coptions['id'] = str_replace("_", "-", $fieldName);

$entity = $this->getView()->get('vv_obj');

Expand Down
8 changes: 6 additions & 2 deletions app/templates/element/datePicker.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
$pickerDate = $pickerDate ?? "";

// Create a date/time picker. The yyyy-MM-dd format is set above in $pickerDate.
$pickerId = 'datepicker-' . $fieldName;
$pickerTarget = $fieldName;

// CAKEPHP transforms snake case variables to kebab when the name has the format of a foreign key.
// As a result searching for the initial key will fail. This is used for use cases
// like the models that use the Tree behavior and have the column parent_id
$pickerId = 'datepicker-' . str_replace("_", "-", $fieldName);
$pickerTarget = str_replace("_", "-", $fieldName);
$pickerTimed = $pickerTimed ?? true; // TODO: set false if date-only
$pickerAmPm = $pickerAmPm ?? false; // TODO: allow change between AM/PM and 24-hour mode

Expand Down
4 changes: 2 additions & 2 deletions app/templates/element/javascript.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@
e.stopPropagation();
$(this).hide();
$(this)[0].dataset.identifier.split(':').forEach( (ident) => {
// CAKEPHP transforms snake case variables to kebab. As a result
// searching for the initial key will fail. This is used for use cases
// CAKEPHP transforms snake case variables to kebab when the name has the format of a foreign key.
// As a result searching for the initial key will fail. This is used for use cases
// like the models that use the Tree behavior and have the column parent_id
let ident_to_snake = ident.replace(/_/g, "-");
let filterId = '#' + ident_to_snake;
Expand Down

0 comments on commit ff60349

Please sign in to comment.