Skip to content
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

Implemented date time fields #82

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

MichalRemis
Copy link

Implemented date/time inputs for Bootstrap4 configuration. (skipped plain SimpleForm because it is complicated - it doesn't have special wrapper for date/time fields and neither marks invalid fields 'is-invalid' when server side validating)

This PR requires DavyJonesLocker/client_side_validations#784 and #81 to work. To make tests pass I included #81 commit in branch and required DavyJonesLocker/client_side_validations#784 branch in Gemfile. Not sure if this is correct approach

@MichalRemis
Copy link
Author

MichalRemis commented Apr 28, 2020

I suppose failing tests are because of missing DavyJonesLocker/client_side_validations#784 in old gemfiles

const oldWrappers = $.extend({}, ClientSideValidations.formBuilders['SimpleForm::FormBuilder'].wrappers)

// It would be probably better to use some stub library but I want to keep it simple
let customWrapperCalled = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi, remember no ES6 here

Copy link
Author

Choose a reason for hiding this comment

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

Yup sorry, I cherry-picked this from #81, I guess I will remove this commit once you merge/implement #81. Fixed in both #81 and this PR.

@@ -42,6 +45,46 @@ ClientSideValidations.formBuilders['SimpleForm::FormBuilder'] = {
element.removeClass('is-invalid');
errorElement.remove();
}
},

get horizontal_multi_select() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I've checked get support and we should be fine with IE >= 9

But is it possible to use the same approach as before?

I mean horizontal_multi_select: function() { } and make it call multi_select with the same params

Copy link
Author

Choose a reason for hiding this comment

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

Not sure what do you mean by "before". What you suggest would require change in

wrapper: function (name) {
return this.wrappers[name] || this.wrappers.default
},

which assumes wrapper key to be value not a function.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I meant "as the others".

which assumes wrapper key to be value not a function.

Got it.

Entirely my fault, but I don't like to see that get there.

I'm fine to set aliases at the end of the file if there is no other approach

const simpleFormFormBuilder = {
  // ...
}

simpleFormFormBuilder.wrappers.horizontal_multi_select = simpleFormFormBuilder.wrappers.multi_select
simpleFormFormBuilder.wrappers.vertical_multi_select = simpleFormFormBuilder.wrappers.multi_select

ClientSideValidations.formBuilders['SimpleForm::FormBuilder'] = simpleFormFormBuilder

Copy link
Author

Choose a reason for hiding this comment

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

Ok, refactored it as you suggested. I just thought with get it would have more clarity.

@tagliala
Copy link
Contributor

I suppose failing tests are because of missing DavyJonesLocker/client_side_validations#784 in old gemfiles

Yes, you should edit appraisals, as well as the travis configuration. Also, this change will work only on compatible versions of CSV, please ignore travis for the moment.

Also, I'm more interested in finishing CSV's side before this. I've a lot of concerns but at the moment I don't have time to elaborate (long story very short: javascript breaks the form removing html fields, should not happen)

…y CSV Javascript form builder for adding/removing of error messages. Before CSV used only form-wide wrapper but field may use custom wrapper specified:

    - by field's `wrapper` attribute
    - by field's type and `wrapper_mappings` attribute
    - by field's type and SimpleForm config `wrapper_mappings`
@@ -42,6 +45,46 @@ ClientSideValidations.formBuilders['SimpleForm::FormBuilder'] = {
element.removeClass('is-invalid');
errorElement.remove();
}
},

get horizontal_multi_select() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I meant "as the others".

which assumes wrapper key to be value not a function.

Got it.

Entirely my fault, but I don't like to see that get there.

I'm fine to set aliases at the end of the file if there is no other approach

const simpleFormFormBuilder = {
  // ...
}

simpleFormFormBuilder.wrappers.horizontal_multi_select = simpleFormFormBuilder.wrappers.multi_select
simpleFormFormBuilder.wrappers.vertical_multi_select = simpleFormFormBuilder.wrappers.multi_select

ClientSideValidations.formBuilders['SimpleForm::FormBuilder'] = simpleFormFormBuilder

@@ -12,15 +12,16 @@ QUnit.module('Validate SimpleForm', {
dataCsv = {
html_settings: {
type: 'SimpleForm::FormBuilder',
error_class: 'error small',
Copy link
Contributor

Choose a reason for hiding this comment

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

small presence had a reason:

399f389

Unfortunately this commit didn't come with a test, so we are not explicitly testing this behavior. 🙏🏼

Copy link
Author

Choose a reason for hiding this comment

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

Ah I see purpose of small is to test if everything works if 2 classes are present. Sorry, I put it back. I was just comparing it with default simple_form setting and thought it should be same.

Copy link
Contributor

Choose a reason for hiding this comment

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

Don't worry, the problem is the missing test, or at least a comment should be present

Copy link
Contributor

Choose a reason for hiding this comment

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

Implemented an explicit test for this use case in CSV: DavyJonesLocker/client_side_validations@a49dd74

Will do the same here

Base automatically changed from master to main January 23, 2021 08:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants