Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions assets/js/magic.js
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,19 @@ $(function() {
},
ignoreTitle: true
});

// Block submission when a data-max-count field is over its limit,
// instead of letting the value silently get truncated on save.
el.find("[data-max-count]").each(function() {
var field = $(this);
var max = field.data("max-count");
field.rules("add", {
maxlength: max,
messages: {
maxlength: "Please use " + max + " characters or fewer."
}
});
});
});

// Dirty forms check, voor meer info: https://github.com/codedance/jquery.AreYouSure
Expand Down
58 changes: 58 additions & 0 deletions cypress/e2e/1_feature_tests/6_1_Warehouse_Locations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
context("6_1_Warehouse_Locations_Test", () => {
// exact-length strings, built programmatically so the boundary is never off-by-one
const Test_label_prefix = "aaa_LocLenTest_";
const Test_label_at_limit = Test_label_prefix.padEnd(50, "X"); // exactly 50 chars
const Test_label_over_limit = Test_label_prefix.padEnd(51, "X"); // exactly 51 chars

function NavigateToNewLocationForm() {
cy.visit('/?action=locations_edit&origin=locations');
}

function FillLocationForm(label) {
cy.get("input[id='field_label']").clear().type(label);
cy.selectOptionByText("box_state_id", "Instock");
}

function ArchiveTestedLocation(label) {
cy.visit('/?action=locations');
cy.get('body').then(($body) => {
if ($body.text().includes(label)) {
cy.checkGridCheckboxByText(label);
cy.get("button[data-testid='reactivate-cms-user']").click();
cy.getConfirmActionButton().click();
cy.waitForAjaxAction("do=archive", "Item deleted");
}
});
}

beforeEach(function () {
cy.setupAjaxActionHook();
cy.loginAsCoordinator();
});

afterEach(function () {
ArchiveTestedLocation(Test_label_at_limit);
});
Comment thread
Copilot marked this conversation as resolved.

it("6_1_1 Rejects a location name over the character limit with an inline error, and does not save it", () => {
NavigateToNewLocationForm();
FillLocationForm(Test_label_over_limit);
cy.getButtonWithText("Save and close").click();

cy.checkQtipWithText("qtip-content", "Please use 50 characters or fewer.");
// still on the form - the too-long name was never submitted
cy.url().should('include', 'action=locations_edit');

cy.visit('/?action=locations');
cy.get('body').should('not.contain', Test_label_prefix);
});

it("6_1_2 Saves a location name that is exactly at the character limit", () => {
NavigateToNewLocationForm();
FillLocationForm(Test_label_at_limit);
cy.getButtonWithText("Save and close").click();

cy.url().should('include', 'action=locations');
cy.getRowWithText(Test_label_at_limit).should('exist');
});
});
37 changes: 37 additions & 0 deletions db/migrations/20260725095602_widen_locations_label_column.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class WidenLocationsLabelColumn extends AbstractMigration
{
/**
* Widens locations.label from varchar(20) to varchar(50) so that
* location names are no longer silently truncated by MySQL on save.
*/
public function up(): void
{
$this->table('locations')
->changeColumn('label', 'string', [
'null' => false,
'limit' => 50,
])
->update()
;
}

/**
* This will truncate labels that exceed the character limit.
*/
public function down(): void
{
$this->table('locations')
->changeColumn('label', 'string', [
'null' => false,
'limit' => 20,
])
->update()
;
}
}
7 changes: 6 additions & 1 deletion include/locations_edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@
$table = 'locations';
$action = 'locations_edit';
$is_admin = $_SESSION['user']['is_admin'];
$labelMaxLength = 50;

if ($_POST) {
// check if you have access to the location you want to update
verify_campaccess_location($_POST['id']);

if (mb_strlen((string) $_POST['label']) > $labelMaxLength) {
throw new Exception("Location name is too long. Please use {$labelMaxLength} characters or fewer.");
}

if (in_array($_POST['box_state_id'][0], ['3', '4', '7', '8'])) {
throw new Exception('You cannot create Locations with this box state!');
}
Expand Down Expand Up @@ -42,7 +47,7 @@
$cmsmain->assign('title', 'Warehouse Location');

addfield('hidden', '', 'id');
addfield('text', 'Label', 'label', ['required' => true]);
addfield('text', 'Label', 'label', ['required' => true, 'maxlength' => $labelMaxLength, 'tooltip' => 'Keeping location names short (max '.$labelMaxLength.' characters) keeps navigation fast for warehouse and distribution teams on mobile.']);
addfield('select', 'Default Status of Boxes', 'box_state_id', ['required' => true, 'tooltip' => 'If a box is moved to this location it will be assigned this status by default.', 'query' => 'SELECT id AS value, label FROM box_state WHERE id in (1,5,6) ORDER BY id']);
addfield('html', 'About Locations', '<p>Locations are physical areas that hold stock. Giving locations a default status for Boxes will help you track of where your stock is going.
<ul>
Expand Down
3 changes: 2 additions & 1 deletion templates/cms_footer.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
<script src="/assets/js/jquery.tablesorter.widgets.js"></script>
<script src="/assets/js/jquery.ui.touch-punch.min.js"></script>
<script src="/assets/jsignature/jquery.signature.js"></script>
<script src="/assets/js/jquery.simplyCountable.js"></script>

<script src="/assets/js/magic.js?v=14"></script>
<script src="/assets/js/magic.js?v=15"></script>
<script src="/assets/js/custom.js?v=14"></script>
<script src="/assets/js/shoppingCart.js?v=2"></script>

Expand Down
11 changes: 0 additions & 11 deletions templates/cms_form_location.tpl

This file was deleted.

2 changes: 1 addition & 1 deletion templates/cms_form_number.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{if $element['locked']}<div class="input-group locked">{/if}
<input type="number" id="field_{$element['field']}" name="{$element['field']}" {if $element['maxlength']}data-max-count="{$element['maxlength']}"{/if} class="form-control{if $element['format']} cms-form-{$element['format']}{/if}{if $element['setformtitle']} setformtitle{/if}" value="{$data[$element['field']]}" {if isset($element['onchange']) or $element['format']}onchange="{if $element['format']}cms_form_{$element['format']}('{$element['field']}');{/if}{$element['onchange']};"{/if} {if isset($element['onkeyup'])}onkeyup="{$element['onkeyup']};"{/if} onblur="{$element['onblur']};" {if $element['minlength']}minlength="{$element['minlength']}"{/if} {if $element['min']}min="{$element['min']}"{/if} {if $element['max']}max="{$element['max']}"{/if} {if $element['readonly'] || $element['locked']}readonly{/if} {if $element['required']}required{/if} {if isset($element['testid'])}data-testid="{$element['testid']}"{/if}>
{if $element['locked']}<span class="input-group-btn"><button class="btn btn-default unlock" type="button"><span class="fa"></span></button></span></div>{/if}
{if $element['maxlength']}<p class="counter-parent safe"><span class="counter">{$element['maxlength']}</span> tekens over van {$element['maxlength']}</p>{/if}
{if $element['maxlength']}<p class="counter-parent safe"><span class="counter">{$element['maxlength']}</span> {$translate['cms_form_charactersleft']|replace:'%n':$element['maxlength']}</p>{/if}
{if $element['tooltip']}{include file="cms_tooltip.tpl" valign=" middle"}{/if}
</div>
</div>
2 changes: 1 addition & 1 deletion templates/cms_form_text.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{if $element['locked']}<div class="input-group locked">{/if}
<input type="text" id="field_{$element['field']}" name="{$element['field']}" {if $element['maxlength']}data-max-count="{$element['maxlength']}"{/if} class="form-control{if $element['format']} cms-form-{$element['format']}{/if}{if $element['setformtitle']} setformtitle{/if}" value="{$data[$element['field']]}"{if isset($element['onchange']) or $element['format']} onchange="{if $element['format']}cms_form_{$element['format']}('{$element['field']}');{/if}{$element['onchange']}"{/if}{if $element['disableautocomplete']} autocomplete="new-password"{/if}{if $element['onkeyup']} onkeyup="{$element['onkeyup']}"{/if}{if $element['onblur']} onblur="{$element['onblur']}"{/if}{if $element['minlength']} minlength="{$element['minlength']}"{/if}{if $element['readonly'] || $element['locked']} readonly{/if}{if $element['disabled']} disabled{/if}{if $element['required']} required{/if}{if isset($element['testid'])} data-testid="{$element['testid']}"{/if}>
{if $element['locked']}<span class="input-group-btn"><button class="btn btn-default unlock" type="button"><span class="fa"></span></button></span></div>{/if}
{if $element['maxlength']}<p class="counter-parent safe"><span class="counter">{$element['maxlength']}</span> tekens over van {$element['maxlength']}</p>{/if}
{if $element['maxlength']}<p class="counter-parent safe"><span class="counter">{$element['maxlength']}</span> {$translate['cms_form_charactersleft']|replace:'%n':$element['maxlength']}</p>{/if}
{if $element['tooltip']}{include file="cms_tooltip.tpl" valign=" middle"}{/if}
</div>
</div>
14 changes: 0 additions & 14 deletions templates/cms_form_url.tpl

This file was deleted.

Loading