Index: chrome/browser/resources/md_bookmarks/edit_dialog.js |
diff --git a/chrome/browser/resources/md_bookmarks/edit_dialog.js b/chrome/browser/resources/md_bookmarks/edit_dialog.js |
index c2a4873c3d14be119985ea00120d3158e52e2efe..31517fe62dafa83819034b6c094fa84d613068f5 100644 |
--- a/chrome/browser/resources/md_bookmarks/edit_dialog.js |
+++ b/chrome/browser/resources/md_bookmarks/edit_dialog.js |
@@ -25,8 +25,10 @@ Polymer({ |
this.isFolder_ = !editItem.url; |
this.titleValue_ = editItem.title; |
- if (!this.isFolder_) |
+ if (!this.isFolder_) { |
+ this.$.url.invalid = false; |
this.urlValue_ = assert(editItem.url); |
+ } |
this.$.dialog.showModal(); |
}, |
@@ -41,13 +43,38 @@ Polymer({ |
isFolder ? 'renameFolderTitle' : 'editBookmarkTitle'); |
}, |
+ /** |
+ * Validates the value of the URL field, returning true if it is a valid URL. |
+ * May modify the value by prepending 'http://' in order to make it valid. |
+ * @return {boolean} |
+ * @private |
+ */ |
+ validateUrl_: function() { |
+ var urlInput = /** @type {PaperInputElement} */ (this.$.url); |
+ var originalValue = this.urlValue_; |
+ |
+ if (urlInput.validate()) |
+ return true; |
+ |
+ this.urlValue_ = 'http://' + originalValue; |
+ |
+ if (urlInput.validate()) |
+ return true; |
+ |
+ this.urlValue_ = originalValue; |
calamity
2017/03/24 04:57:44
Urgh. This is a bit unfortunate. It's a shame you
tsergeant
2017/03/27 05:31:44
Yeah, it's a pity, but at least the URL field vali
|
+ return false; |
+ }, |
+ |
/** @private */ |
onSaveButtonTap_: function() { |
// TODO(tsergeant): Save changes when enter is pressed. |
- // TODO(tsergeant): Verify values. |
var edit = {'title': this.titleValue_}; |
- if (!this.isFolder_) |
+ if (!this.isFolder_) { |
+ if (!this.validateUrl_()) |
+ return; |
+ |
edit['url'] = this.urlValue_; |
+ } |
chrome.bookmarks.update(this.editItem_.id, edit); |
this.$.dialog.close(); |