Skip to content

Commit

Permalink
add option for inputValue
Browse files Browse the repository at this point in the history
in case we want something else than the innerText of element
  • Loading branch information
NicolasCARPi committed Mar 11, 2022
1 parent d49a7a6 commit 8ad789b
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export interface Options {
submit?: string;
submitClasses?: Array<string>;
tooltip?: string;
inputValue?: string;
}

export class Malle {
Expand Down Expand Up @@ -96,6 +97,7 @@ export class Malle {
submit: '',
submitClasses: [],
tooltip: '',
inputValue: '',
};
return Object.assign(defaultOptions, options);
}
Expand Down Expand Up @@ -209,7 +211,18 @@ export class Malle {
input.classList.add(cl);
});
// the value of the input is the current text of the original element
input.value = this.original.innerText;
// but it can also be specified elsewhere
let value;
if (this.opt.inputValue) {
value = this.opt.inputValue;
}
if (this.original.dataset.maInputValue) {
value = this.original.dataset.maInputValue;
}
if (!value) {
value = this.original.innerText;
}
input.value = value;

// PLACEHOLDER
if (this.opt.placeholder) {
Expand Down

0 comments on commit 8ad789b

Please sign in to comment.