Skip to content

Try to fix placeholder application for bureaucracy fields #744

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
43 changes: 27 additions & 16 deletions helper/field.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,25 @@ public function initialize($args)
*/
protected function setVal($value)
{
global $INPUT;

if (!$this->column) {
$value = '';
} else {
$value = $this->replace($value);
$validator = new ValueValidator();
$this->error = !$validator->validateValue($this->column, $value);
if ($this->error) {
foreach ($validator->getErrors() as $error) {
msg(hsc($error), -1);

// This method is called at parsing time, and again on action submit
// we really only want to validate the value on action submit
//
// At parsing time, the value might still be a placeholder. Ideally
// bureaucracy would already handle this. But well...
if($INPUT->post->has('bureaucracy')) {
$validator = new ValueValidator();

$this->error = !$validator->validateValue($this->column, $value);
if ($this->error) {
foreach ($validator->getErrors() as $error) {
msg(hsc($error), -1);
}
}
}
}
Expand Down Expand Up @@ -154,22 +164,23 @@ public function replacementMultiValueCallback($matches)
* Returns a Value object for the current column.
* Special handling for Page and Lookup literal form values.
*
* Used for rendering the field only.
*
* @return Value
*/
protected function createValue()
{
/*
// The value in bureaucracy is always a string, if unset init it.
$preparedValue = $this->opt['value'] ?? '';
if($this->column->isMulti()) {
// multi-value fields are treated as comma-separated lists
$preparedValue = explode(',', $preparedValue);
$preparedValue = array_map('trim', $preparedValue);
$preparedValue = array_filter($preparedValue);
}
*/

// input value or appropriately initialized empty value
$preparedValue = $this->opt['value'] ?? ($this->column->isMulti() ? [] : '');
// apply placeholder replacements
$preparedValue = $this->replace($preparedValue);

// Validating here is actually not a validation, that will happen again in setVal() when
// the form is submitted. instead, here we're using it's data cleanup functionality on the value.
$validator = new ValueValidator();
$validator->validateValue($this->column, $preparedValue);
/** @var string|array $preparedValue is now an array or a string */

// page fields might need to be JSON encoded depending on usetitles config
if (
Expand Down
Loading