-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Telephone link type support in link plugin #2214
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Field for telephone number is marked as required yet it is allowed to have empty value. IMO even without validation editor should disallow inserting empty telephone number.
Additionally there is no unit test for inserting telephone link without validation.
plugins/link/dialogs/link.js
Outdated
var editor = this.getDialog()._.editor, | ||
regExp = editor.config.linkTelNumberValidate_regExp, | ||
msg = editor.config.linkTelNumberValidate_msg, | ||
dialog = this.getDialog(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we move this variable definition earlier, we could use it to get editor
:
editor = dialog._.editor
Microoptimisations – FTW!
tests/plugins/link/link.js
Outdated
bot.dialog( 'link', function( dialog ) { | ||
var expectedNumber = '123456789', | ||
input, | ||
stub = this._stubs.alert = sinon.stub( window, 'alert' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBH creating this._stubs
and whole tearDown
logic seems a little bit like overkill. We got only this one stub, which could be restored with one line of code instead of current 7. Keeping whole stubbing code inside test itself also improves readability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tests/plugins/link/link.js
Outdated
}, | ||
|
||
// (#2154) | ||
'test telephone number link without validation': assertTelephoneLinks(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If test is moved into dedicated function, then this function should be customisable. The bare minimum is the ability to pass object with input and expected output. Otherwise the dedicated function is not reusable in future tests that could be added later, in another issue.
Also asserts could be moved into callback.
plugins/link/dialogs/link.js
Outdated
regExp = editor.config.linkTelNumberValidate_regExp, | ||
msg = editor.config.linkTelNumberValidate_msg, | ||
linkLang = editor.lang.link, | ||
func = CKEDITOR.dialog.validate.notEmpty( linkLang.noTel ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func
could be just inlined into messageWhenEmpty
variable.
plugins/link/dialogs/link.js
Outdated
msg = editor.config.linkTelNumberValidate_msg, | ||
linkLang = editor.lang.link, | ||
func = CKEDITOR.dialog.validate.notEmpty( linkLang.noTel ), | ||
messageWhenEmpty = func.apply( this );; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Double semicolon.
plugins/link/dialogs/link.js
Outdated
return true; | ||
} | ||
|
||
if ( typeof messageWhenEmpty === 'string' || !messageWhenEmpty ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't it be simplified to message !== true
?
plugins/link/dialogs/link.js
Outdated
return messageWhenEmpty; | ||
} | ||
|
||
if ( regExp && !regExp.test( this.getValue() ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that we have built-in CKEDITOR.dialog.validate.regex
, which could simplify the logic.
plugins/link/plugin.js
Outdated
* config.linkTelNumberValidate_regExp = /^[0-9]{9}$/; | ||
* | ||
* @since 4.11.0 | ||
* @cfg {RegExp} [linkTelNumberValidate_regExp] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking about changing names of variables to linkTelNumberRegExp
and linkTelNumberMsg
. ATM only these two config variables in link plugin contain underscore, introducing some kind of inconsistency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! I've just updated manual tests, rephrase message about empty input and fixed some code style issues.
@engineering-this @Comandeer I don't think we made a good choice with the
|
The reason behind putting it in config was the fact that validation will be custom – so the message also could be custom, to include information about the desired format of the telephone number. |
@Comandeer That sounds like a good use case to remember about, though you can still define the default message in the lang file and allow for customization in case of need. So the default lang entry would look pretty much like that:
While you could optionally override it. It could be with config, so you would have a I have emphasized could because I'm not a big fan of adding a config option to customize the error message alone, instead I'd like to see some reusable way to adjust any lang entry during the runtime. TBH I don't know any clear right off the bat (would need to check the code), but you can always do that by listening to |
What is the purpose of this pull request?
New feature
Does your PR contain necessary tests?
All patches which change the editor code must include tests. You can always read more
on PR testing,
how to set the testing environment and
how to create tests
in the official CKEditor documentation.
This PR contains
What changes did you make?
Added new dialog
input[type="tel"]
. And used in in link plugin for inputing phone number in new link type. Also added config options to set validation regex and alert message when validation fails.Closes #2154