Et2Image bugfixes

- No src or default_src gives nothing, not missing image
- Fix etemplate.php parser so buttons that get converted to images still submit
This commit is contained in:
nathan 2022-04-12 10:00:43 -06:00
parent 75e573b6a1
commit 319bd51f80
2 changed files with 23 additions and 9 deletions

View File

@ -156,7 +156,16 @@ function send_template()
preg_match_all('/(^| )([a-z0-9_-]+)="([^"]+)"/', $matches[2], $attrs, PREG_PATTERN_ORDER);
$attrs = array_combine($attrs[2], $attrs[3]);
// replace buttononly tag with noSubmit="true" attribute
if (!empty($matches[1])) $attrs['noSubmit'] = 'true';
if(!empty($matches[1]))
{
$attrs['noSubmit'] = 'true';
}
// novalidation --> noValidation
if(!empty($attrs['novalidation']) && in_array($attrs['novalidation'], ['true', '1'], true))
{
unset($attrs['novalidation']);
$attrs['noValidation'] = 'true';
}
// replace not set background_image attribute with et2-image tag, if not in NM / lists
if(!empty($attrs['image']) && (empty($attrs['background_image']) || $attrs['background_image'] === 'false') &&
!preg_match('/^(index|list)/', $name))
@ -164,12 +173,11 @@ function send_template()
$tag = 'et2-image';
$attrs['src'] = $attrs['image'];
unset($attrs['image']);
}
// novalidation --> noValidation
if (!empty($attrs['novalidation']) && in_array($attrs['novalidation'], ['true', '1'], true))
// Was expected to submit. Images don't have noValidation, so add directly
if(!array_key_exists('onclick', $attrs) && empty($attrs['noSubmit']))
{
unset($attrs['novalidation']);
$attrs['noValidation'] = 'true';
$attrs['onclick'] = 'this.getInstanceManager().submit(this, undefined, ' . $attrs['noValidation'] . ')';
}
}
unset($attrs['background_image']);
return "<$tag ".implode(' ', array_map(function($name, $value)

View File

@ -104,9 +104,15 @@ export class Et2Image extends Et2Widget(LitElement) implements et2_IDetachedDOM
render()
{
let src = this.parse_href(this.src) || this.parse_href(this.default_src);
if(!src)
{
// Hide if no valid image
return '';
}
return html`
<img ${this.id ? html`id="${this.id}"` : ''}
src="${this.parse_href(this.src) || this.parse_href(this.default_src)}"
src="${src}"
alt="${this.label}"
title="${this.statustext || this.label}"
>`;