158,7 → 158,7 |
const PREFIX = 'collect-other-'; |
|
// Ajouter un champ texte pour "Autre" |
function optionAdd( otherId, $target, element, dataName ) { |
function optionAdd( otherId, $target, element, dataName, dataLabel ) { |
$target.after( |
'<div class="control-group">'+ |
'<label'+ |
165,7 → 165,7 |
' for="' + otherId + '"'+ |
' class="' + otherId + '"'+ |
'>'+ |
'Autre option :'+ |
'Autre option "' + dataLabel.toLowerCase() + '" :'+ |
'</label>'+ |
'<input'+ |
' type="text"'+ |
185,29 → 185,32 |
$( '.' + otherId + ', #' + otherId ).remove(); |
} |
|
$( '#form-supp .other' ).each( function() { |
$( '#formulaire .other' ).each( function() { |
if( $( this ).hasClass( 'is-select' ) ) { |
var dataName = $( this ).data( 'name' ), |
otherId = PREFIX + dataName; |
otherId = PREFIX + dataName, |
dataLabel = $( '.select' ).data( 'label' ); |
|
// Insertion du champ "Autre" après les boutons |
optionAdd( otherId, $( this ).parent( '.add-field-select' ), 'select', dataName ); |
optionAdd( otherId, $( this ).parent( '.add-field-select' ), 'select', dataName, dataLabel ); |
} else if ( $( this ).is( ':checked' ) ) { |
var dataName = $( this ).data( 'name' ), |
otherId = PREFIX + dataName, |
element = $( this ).data( 'element' ); |
element = $( this ).data( 'element' ), |
dataLabel = $( this ).data( 'label' ); |
// Insertion du champ "Autre" après les boutons |
optionAdd( otherId, $( this ).parent( 'label' ), element, dataName ); |
optionAdd( otherId, $( this ).parent( 'label' ), element, dataName, dataLabel ); |
} |
}); |
|
$( '#form-supp .select' ).change( function () { |
$( '#formulaire .select' ).change( function () { |
var dataName = $( this ).data( 'name' ), |
otherId = PREFIX + dataName; |
otherId = PREFIX + dataName, |
dataLabel = $( this ).data( 'label' ); |
|
if( 'other' === $( this ).val() ) { |
// Insertion du champ "Autre" après les boutons |
optionAdd( otherId, $( this ).parent( '.add-field-select' ), 'select', dataName ); |
optionAdd( otherId, $( this ).parent( '.add-field-select' ), 'select', dataName, dataLabel ); |
} else { |
// Suppression du champ autre |
optionRemove( otherId ); |
215,13 → 218,14 |
} |
}); |
|
$( '#form-supp input[type=radio]' ).change( function () { |
$( '#formulaire input[type=radio]' ).change( function () { |
var dataName = $( this ).data( 'name' ), |
otherId = PREFIX + dataName; |
otherId = PREFIX + dataName, |
dataLabel = $( this ).data( 'label' ); |
|
if( 'other' === $( this ).val() ) { |
// Insertion du champ "Autre" après les boutons |
optionAdd( otherId, $( this ).parent( 'label' ), 'radio', dataName ); |
optionAdd( otherId, $( this ).parent( 'label' ), 'radio', dataName, dataLabel ); |
} else { |
// Suppression du champ autre |
optionRemove( otherId ); |
229,14 → 233,15 |
} |
}); |
|
$( '#form-supp .list-checkbox .other, #form-supp .checkbox .other' ).click( function () { |
$( '#formulaire .list-checkbox .other, #formulaire .checkbox .other' ).click( function () { |
var dataName = $( this ).data( 'name' ), |
otherId = PREFIX + dataName, |
element = $( this ).data( 'element' ); |
element = $( this ).data( 'element' ), |
dataLabel = $( this ).data( 'label' ); |
|
if( $( this ).is( ':checked' ) ) { |
// Insertion du champ "Autre" après les boutons |
optionAdd( otherId, $( this ).parent( 'label' ), element, dataName ); |
optionAdd( otherId, $( this ).parent( 'label' ), element, dataName, dataLabel ); |
} else { |
// Suppression du champ autre |
optionRemove( otherId ); |
246,7 → 251,7 |
} |
|
function collectOtherOption() { |
$( '#form-supp' ).on( 'change', '.collect-other', function () { |
$( '#formulaire' ).on( 'change', '.collect-other', function () { |
var otherIdSuffix = $( this ).data( 'name' ).replace( '[]', '' ); |
var element = $( this ).data( 'element' ); |
|