Commit b8b23bab authored by Weilun Shi's avatar Weilun Shi Committed by Commit Bot

[NTP] Disable Done button when textfield is empty

Disable Done button on custom link edit dialog when the url is empty or
spaces only.

Screencast:
https://screencast.googleplex.com/cast/NTk2NTU5NzE1ODQwODE5Mnw3OWZhOGVmNi04Mg

Bug: 886665
Change-Id: Ic674894e73ff8dc183af740505fdaa906e5241d9
Reviewed-on: https://chromium-review.googlesource.com/1243678
Commit-Queue: Weilun Shi <sweilun@chromium.org>
Reviewed-by: default avatarKristi Park <kristipark@chromium.org>
Cr-Commit-Position: refs/heads/master@{#594092}
parent 9c42caf6
......@@ -120,19 +120,6 @@ function prepopulateFields(rid) {
}
/**
* Disables the "Done" button until the URL field is modified.
*/
function disableSubmitUntilTextInput() {
$(IDS.DONE).disabled = true;
let reenable = (event) => {
$(IDS.DONE).disabled = false;
$(IDS.URL_FIELD).removeEventListener('input', reenable);
};
$(IDS.URL_FIELD).addEventListener('input', reenable);
}
/**
* Shows the invalid URL error message until the URL field is modified.
*/
......@@ -243,7 +230,7 @@ function handlePostMessage(event) {
document.title = addLinkTitle;
$(IDS.DIALOG_TITLE).textContent = addLinkTitle;
$(IDS.DELETE).disabled = true;
disableSubmitUntilTextInput();
$(IDS.DONE).disabled = true;
// Set accessibility names.
$(IDS.DONE).setAttribute('aria-label', addLinkTitle);
$(IDS.DONE).title = addLinkTitle;
......@@ -352,6 +339,9 @@ function init() {
.addEventListener('focusin', () => changeColor(IDS.URL_FIELD_NAME));
$(IDS.URL_FIELD)
.addEventListener('blur', () => changeColor(IDS.URL_FIELD_NAME));
// Disables the "Done" button when the URL field is empty.
$(IDS.URL_FIELD).addEventListener('input',
() => $(IDS.DONE).disabled = ($(IDS.URL_FIELD).value.trim() === ''));
$(IDS.EDIT_DIALOG).showModal();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment