Customfield validation fixes

- customfield did not pass required setting on to widgets
- link entry did not support required
This commit is contained in:
nathan 2023-01-13 11:28:02 -07:00
parent 1a969c4cfc
commit 374ba994a4
4 changed files with 46 additions and 24 deletions

View File

@ -10,7 +10,7 @@
import {css, html, LitElement, PropertyValues, SlotMixin} from "@lion/core";
import {Et2LinkAppSelect} from "./Et2LinkAppSelect";
import {Et2InputWidget} from "../Et2InputWidget/Et2InputWidget";
import {FormControlMixin, ValidateMixin} from "@lion/form-core";
import {FormControlMixin} from "@lion/form-core";
import {Et2LinkSearch} from "./Et2LinkSearch";
import {Et2Link, LinkInfo} from "./Et2Link";
@ -19,23 +19,25 @@ import {Et2Link, LinkInfo} from "./Et2Link";
*
*
*/
export class Et2LinkEntry extends Et2InputWidget(FormControlMixin(ValidateMixin(SlotMixin(LitElement))))
export class Et2LinkEntry extends Et2InputWidget(FormControlMixin(SlotMixin(LitElement)))
{
static get styles()
{
return [
...super.styles,
css`
:host {
:host {
display: block;
}
:host(.hideApp) ::slotted([slot="app"]) {
}
:host(.hideApp) ::slotted([slot="app"]) {
display: none;
}
.input-group__input {
}
.input-group__input {
gap: 0.5rem;
}
}
`
];
}
@ -155,6 +157,10 @@ export class Et2LinkEntry extends Et2InputWidget(FormControlMixin(ValidateMixin(
updated(changedProperties : PropertyValues)
{
super.updated(changedProperties);
if(changedProperties.has("required"))
{
this._searchNode.required = this.required;
}
if(changedProperties.has("readonly"))
{
this._appNode.readonly = this.readonly;
@ -266,6 +272,8 @@ export class Et2LinkEntry extends Et2InputWidget(FormControlMixin(ValidateMixin(
this._searchNode.value = "";
this._searchNode.clearSearch();
this._searchNode.focus();
this.requestUpdate('value');
}
/**
@ -277,6 +285,9 @@ export class Et2LinkEntry extends Et2InputWidget(FormControlMixin(ValidateMixin(
{
this.classList.add("hideApp");
this.dispatchEvent(new Event("change"));
this.requestUpdate('value');
this.validate();
}
@ -291,6 +302,9 @@ export class Et2LinkEntry extends Et2InputWidget(FormControlMixin(ValidateMixin(
this._searchNode.focus();
this.dispatchEvent(new Event("change"));
this.requestUpdate('value');
this.validate();
}
@ -388,7 +402,7 @@ export class Et2LinkEntry extends Et2InputWidget(FormControlMixin(ValidateMixin(
_inputGroupInputTemplate()
{
return html`
<div class="input-group__input">
<div class="input-group__input" part="control">
<slot name="app"></slot>
<slot name="select"></slot>
</div>

View File

@ -133,6 +133,11 @@ export class Et2LinkSearch extends Et2Select
}
});
}
public validate()
{
// Do not validate
}
}
// @ts-ignore TypeScript is not recognizing that this widget is a LitElement

View File

@ -295,8 +295,8 @@ class Customfields extends Transformer
$type = 'link-to';
}
}
$xml = '<'.$type.' type="'.$type.'" id="'.self::$prefix.$fname.'"/>';
$widget = self::factory($type, $xml, self::$prefix.$fname);
$xml = '<' . $type . ' type="' . $type . '" id="' . self::$prefix . $fname . '" required="' . $field['needed'] . '"/>';
$widget = self::factory($type, $xml, self::$prefix . $fname);
$widget->id = self::$prefix.$fname;
$widget->attrs['type'] = $type;
$widget->set_attrs($xml);

View File

@ -358,10 +358,6 @@ class Link extends Etemplate\Widget
*
* Following attributes get checked:
* - needed: value must NOT be empty
* - min, max: int and float widget only
* - maxlength: maximum length of string (longer strings get truncated to allowed size)
* - preg: perl regular expression incl. delimiters (set by default for int, float and colorpicker)
* - int and float get casted to their type
*
* @param string $cname current namespace
* @param array $expand values for keys 'c', 'row', 'c_', 'row_', 'cont'
@ -377,23 +373,30 @@ class Link extends Etemplate\Widget
$value = $value_in =& self::get_array($content, $form_name);
// keep values added into request by other ajax-functions, eg. files draged into htmlarea (Vfs)
if ((!$value || is_array($value) && !$value['to_id']) && is_array($expand['cont'][$this->id]) && !empty($expand['cont'][$this->id]['to_id']))
if((!$value || is_array($value) && !$value['to_id']) && is_array($expand['cont'][$this->id]) && !empty($expand['cont'][$this->id]['to_id']))
{
if (!is_array($value)) $value = array(
'to_app' => $expand['cont'][$this->id]['to_app'],
);
if(!is_array($value))
{
$value = array(
'to_app' => $expand['cont'][$this->id]['to_app'],
);
}
$value['to_id'] = $expand['cont'][$this->id]['to_id'];
}
if((string)$value === '' && $this->required)
{
self::set_validation_error($form_name, lang('Field must not be empty !!!'), '');
return;
}
// Link widgets can share IDs, make sure to preserve values from others
$already = self::get_array($validated,$form_name);
$already = self::get_array($validated, $form_name);
if($already != null)
{
$value = array_merge((array)$value, $already);
$value = array_merge((array)$value, $already);
}
// Automatically do link if user selected entry but didn't click 'Link' button
$link = self::get_array($content, self::form_name($cname, $this->id . '_link_entry'));
if($this->type =='link-to' && is_array($link) && $link['app'] && $link['id'] )
if($this->type == 'link-to' && is_array($link) && $link['app'] && $link['id'])
{
// Do we have enough information to link automatically?
if(is_array($value) && $value['to_id'])