Implement onlyEmail option for UrlEmailReadonly

This commit is contained in:
hadi 2023-06-22 14:37:15 +02:00
parent 29d159ea29
commit a4109439e1
2 changed files with 13 additions and 5 deletions

View File

@ -195,16 +195,16 @@ export class Et2EmailTag extends Et2Tag
if(!this.onlyEmail && Et2EmailTag.email_cache[this.value])
{
// Append current value as email, data may have work & home email in it
content = (Et2EmailTag.email_cache[this.value]?.n_fn || "") + " <" + (this.splitEmail(this.value)?.email || this.value) + ">"
content = (Et2EmailTag.email_cache[this.value]?.n_fn || "") + " <" + (Et2EmailTag.splitEmail(this.value)?.email || this.value) + ">"
}
if (this.onlyEmail)
{
const split = this.splitEmail(content);
const split = Et2EmailTag.splitEmail(content);
content = split.email || this.value;
}
else if(!this.fullEmail)
{
const split = this.splitEmail(content);
const split = Et2EmailTag.splitEmail(content);
content = split.name || split.email;
}
return html`
@ -264,7 +264,7 @@ export class Et2EmailTag extends Et2Tag
*
* @return {name:string, email:string}
*/
public splitEmail(email_string) : { name : string, email : string }
public static splitEmail(email_string) : { name : string, email : string }
{
let split = {name: "", email: email_string};
if(email_string && email_string.indexOf('<') !== -1)

View File

@ -11,6 +11,7 @@
import {IsEmail} from "../Validators/IsEmail";
import {Et2UrlEmail} from "./Et2UrlEmail";
import {Et2UrlReadonly} from "./Et2UrlReadonly";
import {Et2EmailTag} from "../Et2Select/Tag/Et2EmailTag";
/**
* @customElement et2-url-email_ro
@ -35,6 +36,13 @@ export class Et2UrlEmailReadonly extends Et2UrlReadonly
contactPlus: {
type: Boolean,
},
/**
* set to true to always show just the email
* Mutually exclusive with fullEmail!
*/
onlyEmail: {
type: Boolean
}
};
}
@ -45,7 +53,7 @@ export class Et2UrlEmailReadonly extends Et2UrlReadonly
if (!this.fullEmail && val && val.indexOf('<') !== -1)
{
const parts = val.split('<');
if (parts[0])
if (parts[0] && !this.onlyEmail)
{
super.statustext = parts[1].substring(0, parts[1].length-1);
val = parts[0].trim();