-
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
Open
MichalRemis
wants to merge
5
commits into
DavyJonesLocker:main
Choose a base branch
from
MichalRemis:implemented-date-time-fields
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
53f6325
Implemented field's specific wrapper_names to be passed to and used b…
MichalRemis d9b70c9
Add support for Date/Time inputs (bootstrap4)
MichalRemis 5dbb4d4
Plain SimpleForm Date/Time WIP
MichalRemis d40e9ae
RemovePlainSimpleForm
MichalRemis 32112c1
Refactored MultiSelect JS builder and fix test
MichalRemis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
error_class: 'error small', // 'small' class is present to test 399f389 | ||
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 | ||
}) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
small
presence had a reason:399f389
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 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.
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.
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 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