-
Notifications
You must be signed in to change notification settings - Fork 102
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
base: main
Are you sure you want to change the base?
Changes from 4 commits
53f6325
d9b70c9
5dbb4d4
d40e9ae
32112c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,15 +12,16 @@ QUnit.module('Validate SimpleForm', { | |
dataCsv = { | ||
html_settings: { | ||
type: 'SimpleForm::FormBuilder', | ||
error_class: 'error small', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Unfortunately this commit didn't come with a test, so we are not explicitly testing this behavior. 🙏🏼 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
error_class: 'error', | ||
error_tag: 'span', | ||
wrapper_error_class: 'field_with_errors', | ||
wrapper_tag: 'div', | ||
wrapper_class: 'input', | ||
wrapper: 'default' | ||
}, | ||
validators: { | ||
'user[name]': { presence: [{ message: 'must be present' }], format: [{ message: 'is invalid', 'with': { options: 'g', source: '\\d+' } }] } | ||
'user[name]': { presence: [{ message: 'must be present' }], format: [{ message: 'is invalid', 'with': { options: 'g', source: '\\d+' } }] }, | ||
'user[date_of_birth]': { presence: [{ message: 'must be present' }] } | ||
} | ||
} | ||
|
||
|
@@ -40,6 +41,12 @@ QUnit.module('Validate SimpleForm', { | |
type: 'text' | ||
})) | ||
.append($('<label for="user_name">Name</label>')) | ||
.append($('<input />', { | ||
name: 'user[date_of_birth]', | ||
id: 'date_of_birth', | ||
type: 'text', | ||
'data-client-side-validations-wrapper': 'custom_date_wrapper' | ||
})) | ||
$('form#new_user').validate() | ||
} | ||
}) | ||
|
@@ -82,3 +89,22 @@ QUnit.test('Validate pre-existing error blocks are re-used', function (assert) { | |
assert.ok(input.parent().find('span.error:contains("is invalid")').length === 1) | ||
assert.ok(form.find('span.error').length === 1) | ||
}) | ||
|
||
QUnit.test('Validate correct JS Builder\'s wrapper is called for custom_wrapper', function (assert) { | ||
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi, remember no ES6 here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
ClientSideValidations.formBuilders['SimpleForm::FormBuilder'].wrappers['custom_date_wrapper'] = { | ||
add: function(element, settings, message) { customWrapperCalled=true; }, | ||
remove: function(element, settings) {} | ||
} | ||
|
||
var form = $('form#new_user'); | ||
var input = form.find('input#date_of_birth') | ||
input.trigger('focusout') | ||
|
||
assert.ok(customWrapperCalled); | ||
ClientSideValidations.formBuilders['SimpleForm::FormBuilder'].wrappers = oldWrappers | ||
}) |
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'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 callmulti_select
with the same paramsThere 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.
Not sure what do you mean by "before". What you suggest would require change in
which assumes wrapper key to be value not a function.
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.
Sorry, I meant "as the others".
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
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.
Ok, refactored it as you suggested. I just thought with
get
it would have more clarity.