Skip to content
This repository was archived by the owner on Aug 7, 2020. It is now read-only.

Conversation

@JDownloader
Copy link
Contributor

No description provided.

@JDownloader JDownloader force-pushed the feature/field-custom-error-messages branch from 346dddd to 0e32543 Compare March 1, 2018 13:47
@JDownloader JDownloader requested a review from neolitec March 2, 2018 14:51
@neolitec neolitec changed the title ✨ feat(field): add custom error message and ng-pattern support feat(field): add custom error message and ng-pattern support Mar 2, 2018

### error-messages

| Attribute | Type | Binding | One-time binding | Values | Default | Description |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not really a tag attribute, so... some columns should not be there like "Binding", "One-time binding"...
Maybe it's could be sufficient to only show the default object and explaining that it can be overridden.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it could be replaced with a configuration section like for pagination component.
An exemple of provider configuration with default message could be interesting

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the binding is for the object containing the messages, I was was not sure on how to present it. I will take a look at the pagination section to try to improve that.

minlength: ["minlength", "ng-minlength"],
maxlength: ["maxlength", "ng-maxlength"]
maxlength: ["maxlength", "ng-maxlength"],
custumValidation: ["pattern", "ng-pattern"]
Copy link
Contributor

@neolitec neolitec Mar 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

custum -> custom
Or could it be simply named pattern so that it can be reused with {{pattern}} in error message?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for pattern


describe("with validation", () => {
it("should retrieve custom error messages", () => {
const message = "Username must be a least 6 characters.";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(optional but should not be) I don't remember if it has been done before but I think you should also test that interpolation works in custom messages.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be done in a new test, only for testing the interpolation.

id="username"
name="username"
ng-model="$ctrl.user.username"
ng-pattern="/^[a-z]{3,8}$/">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(optional) Maybe [a-zA-Z] to exactly match with the error message.


## API

### oui-datagrid
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why oui-datagrid? copy/paste error before your pull-request

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tremblaymath I'm not what you want about that subtitle

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oui-datagrid has no sense in field component documentation.
To remove

</oui-field>
<oui-field label="{{'Username'}}"
error-messages="{pattern: 'Username must be alphabetic with a length between 3 and 8.'}">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should add a helper text "Username must be alphabetic with a length between 3 and 8.", it will be helpful to trigger error. It could be interesting for other examples too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An helper text or an error, not both of them...
Maybe something like "This input is valid only if..." for helper text.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would avoid also doing both, I think the error is easy to trigger like the lastname field.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

easy to trigger yes!
But the user doesn't know the validations without clicking on "Show the example" and reading the code.
"I think the error is easy to trigger like the lastname field." There is already a help text for lastname "At least 3 chars" and it's a good thing that we should reproduce


### error-messages

| Attribute | Type | Binding | One-time binding | Values | Default | Description |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it could be replaced with a configuration section like for pagination component.
An exemple of provider configuration with default message could be interesting

minlength: ["minlength", "ng-minlength"],
maxlength: ["maxlength", "ng-maxlength"]
maxlength: ["maxlength", "ng-maxlength"],
custumValidation: ["pattern", "ng-pattern"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for pattern

});
});

describe("with validation", () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good test for custom message!
We should test default error messages too. Almost identical to this one

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but it the test should not enforce a string but verify it's actually using the one from the provider

Copy link
Contributor

@tremblaymath tremblaymath Mar 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I agree, provider should be mocked and we should only "verify it's actually using the one from the provider"
There was already missing tests before you started

</oui-field>
<oui-field label="{{'Username'}}"
error-messages="{pattern: 'Username must be alphabetic with a length between 3 and 8.'}">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to see parameters in this example

@tremblaymath tremblaymath requested a review from neolitec March 5, 2018 17:16
@tremblaymath tremblaymath dismissed neolitec’s stale review March 5, 2018 17:18

No blocking comments. Doc and tests could be improved after

@tremblaymath tremblaymath force-pushed the feature/field-custom-error-messages branch from 8b9b923 to 482a8fa Compare March 5, 2018 17:27
@tremblaymath tremblaymath merged commit f26267c into master Mar 5, 2018
@tremblaymath tremblaymath deleted the feature/field-custom-error-messages branch March 5, 2018 17:29
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Development

Successfully merging this pull request may close these issues.

5 participants