I want to have field in Backpack Laravel as an input with format of mm:ss ? i tried the code below but it's giving me format of hh:mm :
<input
type="time"
min="00:00"
max="59:59"
name="{{ $field['name'] }}"
value="{{ old($field['name']) ? old($field['name']) : (isset($field['value']) ? $field['value'] : (isset($field['default']) ? $field['default'] : '' )) }}"
@include('crud::fields.inc.attributes')
>
How can i do that ?
This is my solution using JS :
@include('crud::fields.inc.wrapper_start')
<label>{!! $field['label'] !!}</label>
<input
type="text"
id="time"
placeholder="--:--"
maxlength="5"
name="{{ $field['name'] }}"
value="{{ old($field['name']) ? old($field['name']) : (isset($field['value']) ? $field['value'] : (isset($field['default']) ? $field['default'] : '' )) }}"
@include('crud::fields.inc.attributes')
>
{{-- HINT --}}
@if (isset($field['hint']))
<p class="help-block">{!! $field['hint'] !!}</p>
@endif
@include('crud::fields.inc.wrapper_end')
@push('crud_fields_scripts')
<script>
(function($, undefined) {
"use strict";
$(function() {
$('#time').on( "keyup", function( event ) {
let selection = window.getSelection().toString();
if ( selection !== '' ) {
return;
}
if ( $.inArray( event.keyCode, [38,40,37,39] ) !== -1 ) {
return;
}
let $this = $(this);
let input = $this.val();
input = input.replace(/[\W\s\._\-\D]+/g, '');
let split = 2;
let chunk = [];
for (let i = 0, len = input.length; i < len; i += split) {
chunk.push( input.substr( i, split ) );
}
$this.val(function() {
return chunk.join(":");
});
} );
});
})(jQuery);
</script>
@endpush
this worked for me:
CRUD::addField([
'name' => 'accounting_date',
'type' => 'datetime_picker',
'label' => 'Abrechnungszeitraum',
'wrapper' => ['class' => 'form-group col-md-3'],
'datetime_picker_options' => [
'format' => 'mm:ss',
'language' => 'de',
]
]);