Skip to content

Commit

Permalink
hiddenName option added. fixes #377
Browse files Browse the repository at this point in the history
  • Loading branch information
amsul committed Apr 12, 2014
1 parent ea4bbf2 commit ff0cc0c
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 14 deletions.
23 changes: 17 additions & 6 deletions lib/picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -667,19 +667,30 @@ function PickerConstructor( ELEMENT, NAME, COMPONENT, OPTIONS ) {
*/
function prepareElementHidden() {

var id = [
typeof SETTINGS.hiddenPrefix == 'string' ? SETTINGS.hiddenPrefix : '',
typeof SETTINGS.hiddenSuffix == 'string' ? SETTINGS.hiddenSuffix : '_submit'
]
var id,
name

if ( SETTINGS.hiddenName === true ) {
id = ELEMENT.name + '_hidden'
name = ELEMENT.name
ELEMENT.name = ''
}
else {
name = [
typeof SETTINGS.hiddenPrefix == 'string' ? SETTINGS.hiddenPrefix : '',
typeof SETTINGS.hiddenSuffix == 'string' ? SETTINGS.hiddenSuffix : '_submit'
]
name = id = name[0] + ELEMENT.name + name[1]
}

P._hidden = $(
'<input ' +
'type=hidden ' +

// Create the name and ID by using the original
// input’s with a prefix and suffix.
'name="' + id[0] + ELEMENT.name + id[1] + '"' +
'id="' + id[0] + ELEMENT.id + id[1] + '"' +
'name="' + name + '"' +
'id="' + id + '"' +

// If the element has a value, set the hidden value as well.
(
Expand Down
2 changes: 1 addition & 1 deletion lib/translations/hu_HU.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ jQuery.extend( jQuery.fn.pickadate.defaults, {
firstDay: 1,
format: 'yyyy. mmmm dd.',
formatSubmit: 'yyyy/mm/dd'
});
});
13 changes: 6 additions & 7 deletions tests/dev/date.htm
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,15 @@ <h3><label for="input_01">Pick a date. Go ahead...</label></h3>

<script type="text/javascript">

var $input = $( '.datepicker' ).pickadate()
var $input = $( '.datepicker' ).pickadate({
formatSubmit: 'yyyy-mm-dd',
hiddenName: true,
})

var picker = $input.pickadate('picker')

console.log(picker.get('select'));

picker.set('select', new Date())
picker.clear()

console.log(picker.get('select'));
console.log(picker.$node[0])
console.log(picker._hidden)

// $('button').on('click', function() {
// picker.set('disable', true);
Expand Down
21 changes: 21 additions & 0 deletions tests/units/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,27 @@ test( 'No hidden prefix & suffix', function() {
strictEqual( picker.$node[0].name, picker._hidden.name, 'Correct hidden element `name`' )
})

module( 'Formatting setup', {
setup: function() {
$DOM.append( $INPUT.clone().attr( 'name', 'picker' ) )
var $input = $DOM.find( 'input' ).pickadate({
formatSubmit: 'yyyy/mm/dd',
hiddenName: true
})
this.picker = $input.pickadate( 'picker' )
},
teardown: function() {
this.picker.stop()
$DOM.empty()
}
})

test( 'Hidden name replaces visible name', function() {
var picker = this.picker
strictEqual( picker.$node[0].name, '', 'Visible element has no `name`')
strictEqual(picker._hidden.name, 'picker', 'Correct hidden element `name`' )
})




Expand Down

0 comments on commit ff0cc0c

Please sign in to comment.