[FIX] web_editor: Link(Dialog/Tools) label input field

Before this commit, any changes made to label input field were lost when
the LinkDialog or LinkTools component was re-rendered.

This commit fixes it without leveraging OWL's reactivity/declarative
approach, because most of the code in these components is imperative and
not yet converted to the OWL paradigm, leaving such refactor to be done
in the master branch.

Part-of: odoo/odoo#136278
This commit is contained in:
Rodolpho Lima
2023-09-25 11:30:13 +00:00
parent 7fe1731c66
commit e881bc6284
2 changed files with 6 additions and 6 deletions
@@ -102,6 +102,7 @@ export class Link extends Component {
this._updateOptionsUI();
this._setUrl({ shouldFocus: this.props.shouldFocusUrl });
this.$el[0].querySelector('#o_link_dialog_label_input').value = this.state.originalText;
}
/**
* @override
@@ -526,8 +527,7 @@ export class Link extends Component {
}
const linkNode = this.$link[0] || this.state.range.cloneContents();
const linkText = linkNode.innerText;
this.state.initialContent = linkText.replace(/[ \t\r\n]+/g, ' ');
this.state.originalText = this.state.initialContent;
this.state.originalText = linkText.replace(/[ \t\r\n]+/g, ' ');
if (linkNode instanceof DocumentFragment) {
this.state.originalHTML = $('<fakeEl>').append(linkNode).html();
} else {
@@ -535,12 +535,12 @@ export class Link extends Component {
}
this.state.url = this.$link.attr('href') || '';
} else {
this.state.initialContent = this.state.initialContent ? this.state.initialContent.replace(/[ \t\r\n]+/g, ' ') : '';
this.state.originalText = this.state.originalText ? this.state.originalText.replace(/[ \t\r\n]+/g, ' ') : '';
}
if (!this.state.url) {
const urls = this.state.initialContent.match(OdooEditorLib.URL_REGEX_WITH_INFOS);
const urls = this.state.originalText.match(OdooEditorLib.URL_REGEX_WITH_INFOS);
if (urls) {
this.state.url = urls[0];
}
+2 -2
View File
@@ -24,7 +24,7 @@
<div t-attf-class="mb-3 row#{props.needLabel ? '' : ' d-none'}">
<label class="col-form-label col-md-3" for="o_link_dialog_label_input">Link Label</label>
<div class="col-md-9">
<input type="text" name="label" class="form-control" id="o_link_dialog_label_input" required="required" t-att-value="this.state.initialContent" t-ref="inputText"/>
<input type="text" name="label" class="form-control" id="o_link_dialog_label_input" required="required" t-ref="inputText"/>
</div>
</div>
<div t-attf-class="mb-3 row o_url_input#{state.isButton ? ' d-none' : ''}">
@@ -129,7 +129,7 @@
<we-title>Label</we-title>
<we-input class="o_we_user_value_widget">
<div>
<input name="label" id="o_link_dialog_label_input" t-att-value="this.state.initialContent" type="text"/>
<input name="label" id="o_link_dialog_label_input" type="text"/>
</div>
</we-input>
</we-row>