-
Notifications
You must be signed in to change notification settings - Fork 920
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
[4.1][Feature] New field type - Toggle Field Visibility #165
Changes from all commits
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 |
---|---|---|
@@ -0,0 +1,103 @@ | ||
<!-- radio toggle --> | ||
@php | ||
$optionPointer = 0; | ||
$optionValue = old($field['name']) ? old($field['name']) : (isset($field['value']) ? $field['value'] : (isset($field['default']) ? $field['default'] : '' )); | ||
@endphp | ||
|
||
<div @include('crud::inc.field_wrapper_attributes') > | ||
|
||
<div> | ||
<label>{!! $field['label'] !!}</label> | ||
</div> | ||
|
||
@if( isset($field['options']) && is_array($field['options']) ) | ||
|
||
@foreach ($field['options'] as $value => $label ) | ||
@php ($optionPointer++) | ||
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. Is the |
||
|
||
@if( isset($field['inline']) && $field['inline'] ) | ||
|
||
<label class="radio-inline" for="{{$field['name']}}_{{$optionPointer}}"> | ||
<input data-field-toggle="{{ json_encode($field['hide_when']) }}" type="radio" id="{{$field['name']}}_{{$optionPointer}}" name="{{$field['name']}}" value="{{$value}}" {{$optionValue!=='' && $optionValue == $value ? ' checked': ''}}> {!! $label !!} | ||
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.
|
||
</label> | ||
|
||
@else | ||
|
||
<div class="radio"> | ||
<label for="{{$field['name']}}_{{$optionPointer}}"> | ||
<input data-field-toggle="{{ json_encode($field['hide_when']) }}" type="radio" id="{{$field['name']}}_{{$optionPointer}}" name="{{$field['name']}}" value="{{$value}}" {{$optionValue!=='' && $optionValue == $value ? ' checked': ''}}> {!! $label !!} | ||
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. see above re spacing. |
||
</label> | ||
</div> | ||
|
||
@endif | ||
|
||
@endforeach | ||
|
||
@endif | ||
|
||
{{-- HINT --}} | ||
@if (isset($field['hint'])) | ||
<p class="help-block">{!! $field['hint'] !!}</p> | ||
@endif | ||
|
||
</div> | ||
|
||
{{-- ########################################## --}} | ||
{{-- Extra CSS and JS for this particular field --}} | ||
{{-- If a field type is shown multiple times on a form, the CSS and JS will only be loaded once --}} | ||
@if ($crud->checkIfFieldIsFirstOfItsType($field, $fields)) | ||
|
||
{{-- FIELD CSS - will be loaded in the after_styles section --}} | ||
@push('crud_fields_styles') | ||
|
||
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. NL? |
||
@endpush | ||
|
||
{{-- FIELD JS - will be loaded in the after_scripts section --}} | ||
@push('crud_fields_scripts') | ||
<script> | ||
jQuery(document).ready(function($){ | ||
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. Is there a reason we're spelling jQuery here but using |
||
|
||
window.$hiddenFields = window.$hiddenFields || {}; | ||
|
||
var $toggle = function( $radio ){ | ||
|
||
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. NL? |
||
$hideWhen = $radio.data('field-toggle'), | ||
$value = $radio.val(), | ||
$radioSet = $radio.attr('name'); | ||
|
||
$hiddenFields[ $radioSet ] = $hiddenFields[ $radioSet ] || []; | ||
|
||
if( Object.keys($hiddenFields[ $radioSet ]).length ){ | ||
$.each($hiddenFields[ $radioSet ], function(idx, field){ | ||
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. Ok, I have to ask, everything has gotten the evil $ that isn't needed in JS, why not the function parameters? 👿 |
||
field.show(); | ||
}); | ||
$hiddenFields[ $radioSet ] = []; | ||
} | ||
|
||
if( typeof $hideWhen[ $value ] !== undefined ){ | ||
$.each($hideWhen[ $value ], function(idx, name){ | ||
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. See my impish questin above :P |
||
|
||
var f = $('[name="'+name+'"]').parents('.form-group'); | ||
|
||
if( f.length ){ | ||
$hiddenFields[ $radioSet ].push(f); | ||
f.hide(); | ||
} | ||
}); | ||
} | ||
}; | ||
|
||
$('input[data-field-toggle]').on('change', function(){ | ||
return $toggle( $(this) ); | ||
}); | ||
|
||
$('input[data-field-toggle]:checked').each(function(){ | ||
return $toggle( $(this) ); | ||
}); | ||
}); | ||
</script> | ||
@endpush | ||
|
||
@endif | ||
{{-- End of Extra CSS and JS --}} | ||
{{-- ########################################## --}} |
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.
Ternaries in ternaries. Icck.