@@ -538,137 +538,100 @@ public static function renderFields()
538538
539539 $ errors = self ::renderErrors ();
540540
541- // $output = $errors;
542- // $output .= '
543- // <div id="filter" class="card mb-3">
544- // <div class="card-header">
545- // <a class="pointer" onclick="$(\'#filter .card-body\').toggleClass(\'collapse\');$(this).find(\'i\').toggleClass(\'fa-minus-square\');$(\'#id\').focus()">
546- // Filter
547- // <div class="float-right">
548- // <i class="fa fa-plus-square'.(self::$mode == 'opened' || $filterFields['act'] === 'search' ? ' fa-minus-square' : '').'" aria-hidden="true"></i>
549- // </div>
550- // </a>
551- // </div>
552- // <div class="card-body py-1'.(self::$mode == 'opened' || $filterFields['act'] === 'search' ? '' : ' collapse').'">
553- // <form action="'.self::getSubmitRoute().'" method="GET">
554- // <input type="hidden" name="act" value="search">'.PHP_EOL;
555-
556- $ count = 0 ;
557- $ filterFieldsContent = '<div class="row mb-n2"> ' .PHP_EOL ;
558- foreach ($ filters as $ key => $ filter ) {
559-
560- // Skip act field
561- if ($ key === 'act ' ) {
562- continue ;
563- }
541+ $ count = 0 ;
542+ $ filterFieldsContent = '<div class="row mb-n2"> ' .PHP_EOL ;
543+ foreach ($ filters as $ key => $ filter ) {
544+ // Skip act field
545+ if ($ key === 'act ' ) {
546+ continue ;
547+ }
564548
565- // Don't show disabled filter options
566- if (!empty ($ filter ['disabled ' ])) {
567- continue ;
568- }
549+ // Don't show disabled filter options
550+ if (!empty ($ filter ['disabled ' ])) {
551+ continue ;
552+ }
569553
570- // Specify html options
571- $ htmlOptions = ['id ' => $ key , 'name ' => $ key , 'class ' => 'form-control form-control-sm ' ];
572- if (! empty ($ filter ['htmlOptions ' ])) {
573- $ htmlOptions = array_merge ($ htmlOptions , $ filter ['htmlOptions ' ]);
574- }
554+ // Specify html options
555+ $ htmlOptions = ['id ' => $ key , 'name ' => $ key , 'class ' => 'form-control form-control-sm ' ];
556+ if (! empty ($ filter ['htmlOptions ' ])) {
557+ $ htmlOptions = array_merge ($ htmlOptions , $ filter ['htmlOptions ' ]);
558+ }
575559
576- // Split rows in filter after each 4 fields
577- if ($ count != 0 && $ count % self ::$ fieldsInRow == 0 ) {
578- $ filterFieldsContent .= '</div> ' .PHP_EOL ;
579- $ filterFieldsContent .= '<div class="row mb-n2"> ' .PHP_EOL ;
580- }
560+ // Split rows in filter after each 4 fields
561+ if ($ count != 0 && $ count % self ::$ fieldsInRow == 0 ) {
562+ $ filterFieldsContent .= '</div> ' .PHP_EOL ;
563+ $ filterFieldsContent .= '<div class="row mb-n2"> ' .PHP_EOL ;
564+ }
581565
582- $ title = $ filter ['title ' ] ?? $ key ;
583- $ type = $ filter ['type ' ] ?? 'string ' ;
584- $ source = $ filter ['source ' ] ?? [];
585- $ value = isset ($ filterFields [$ key ]) ? $ filterFields [$ key ] : '' ;
586-
587- $ filterFieldsContent .= '<div class="col-md- ' .(self ::$ fieldsInRow == 6 ? 2 : 3 ).'"> ' .PHP_EOL ;
588- $ filterFieldsContent .= '<div class="form-group"> ' .PHP_EOL ;
589- $ filterFieldsContent .= '<label for=" ' .$ key .'" class="col-form-label"> ' .$ title .'</label> ' .PHP_EOL ;
590-
591- switch ($ type ) {
592- case 'int ' :
593- case 'integer ' :
594- $ filterFieldsContent .= '<input type="number" min="1" id=" ' .$ htmlOptions ['id ' ].'" name=" ' .$ htmlOptions ['name ' ].'" class=" ' .$ htmlOptions ['class ' ].'" value=" ' .$ value .'"> ' .PHP_EOL ;
595- break ;
596-
597- case 'date ' :
598- $ filterFieldsContent .= '<input type="date" id=" ' .$ htmlOptions ['id ' ].'" name=" ' .$ htmlOptions ['name ' ].'" class=" ' .$ htmlOptions ['class ' ].'" value=" ' .$ value .'"> ' .PHP_EOL ;
599- break ;
600-
601- case 'set ' :
602- case 'user_status ' :
603- case 'user_active ' :
604- $ filterFieldsContent .= '<select id=" ' .$ htmlOptions ['id ' ].'" name=" ' .$ htmlOptions ['name ' ].'" class=" ' .$ htmlOptions ['class ' ].'"> ' .PHP_EOL ;
605- $ filterFieldsContent .= '<option value=""></option> ' .PHP_EOL ;
606- foreach ($ source as $ sourceValue => $ sourceLabel ) {
607- $ filterFieldsContent .= '<option value=" ' .$ sourceValue .'" ' .($ value != '' && $ sourceValue == $ value ? ' selected ' : '' ).'> ' .$ sourceLabel .'</option> ' .PHP_EOL ;
608- }
609- $ filterFieldsContent .= '</select> ' .PHP_EOL ;
610- break ;
611-
612- case 'url_parameter ' :
613- $ filterFieldsContent .= '<input type="hidden" name=" ' .$ htmlOptions ['name ' ].'" value=" ' .$ value .'"> ' .PHP_EOL ;
614- break ;
615-
616- case 'user_role ' :
617- $ rolesList = [];
618- foreach ($ source as $ vVal => $ vLabel ) {
619- $ rolesList [] = ['value ' => $ vVal , 'label ' => $ vLabel ];
620- }
621-
622- // Selected roles for milti-select
623- $ role = [];
624- if ( ! empty ($ value )) {
625- if (is_string ($ value )) {
626- $ value = explode (', ' , $ value );
627- }
628- $ values = array_filter ($ value );
629- foreach ($ values as $ vLabel ) {
630- if (isset ($ source [$ vLabel ])) {
631- $ role [] = ['value ' => $ vLabel , 'label ' => $ source [$ vLabel ]];
632- }
633- }
634- }
566+ $ title = $ filter ['title ' ] ?? $ key ;
567+ $ type = $ filter ['type ' ] ?? 'string ' ;
568+ $ source = $ filter ['source ' ] ?? [];
569+ $ value = isset ($ filterFields [$ key ]) ? $ filterFields [$ key ] : '' ;
570+
571+ $ filterFieldsContent .= '<div class="col-md- ' .(self ::$ fieldsInRow == 6 ? 2 : 3 ).'"> ' .PHP_EOL ;
572+ $ filterFieldsContent .= '<div class="form-group"> ' .PHP_EOL ;
573+ $ filterFieldsContent .= '<label for=" ' .$ key .'" class="col-form-label"> ' .$ title .'</label> ' .PHP_EOL ;
574+
575+ switch ($ type ) {
576+ case 'int ' :
577+ case 'integer ' :
578+ $ filterFieldsContent .= '<input type="number" min="1" id=" ' .$ htmlOptions ['id ' ].'" name=" ' .$ htmlOptions ['name ' ].'" class=" ' .$ htmlOptions ['class ' ].'" value=" ' .$ value .'"> ' .PHP_EOL ;
579+ break ;
580+
581+ case 'date ' :
582+ $ filterFieldsContent .= '<input type="date" id=" ' .$ htmlOptions ['id ' ].'" name=" ' .$ htmlOptions ['name ' ].'" class=" ' .$ htmlOptions ['class ' ].'" value=" ' .$ value .'"> ' .PHP_EOL ;
583+ break ;
584+
585+ case 'set ' :
586+ case 'user_status ' :
587+ case 'user_active ' :
588+ $ filterFieldsContent .= '<select id=" ' .$ htmlOptions ['id ' ].'" name=" ' .$ htmlOptions ['name ' ].'" class=" ' .$ htmlOptions ['class ' ].'"> ' .PHP_EOL ;
589+ $ filterFieldsContent .= '<option value=""></option> ' .PHP_EOL ;
590+ foreach ($ source as $ sourceValue => $ sourceLabel ) {
591+ $ filterFieldsContent .= '<option value=" ' .$ sourceValue .'" ' .($ value != '' && $ sourceValue == $ value ? ' selected ' : '' ).'> ' .$ sourceLabel .'</option> ' .PHP_EOL ;
592+ }
593+ $ filterFieldsContent .= '</select> ' .PHP_EOL ;
594+ break ;
635595
636- $ filterFieldsContent .= '<vue-multiselect :id=" \'' .$ htmlOptions ['id ' ].'\'" :options= \'' .json_encode ($ rolesList ).'\' :values= \'' .json_encode ($ role ).'\' :placeholder-text=" \'Select Role \'"></vue-multiselect> ' .PHP_EOL ;
637- break ;
596+ case 'url_parameter ' :
597+ $ filterFieldsContent .= '<input type="hidden" name=" ' .$ htmlOptions ['name ' ].'" value=" ' .$ value .'"> ' .PHP_EOL ;
598+ break ;
599+
600+ case 'user_role ' :
601+ $ rolesList = [];
602+ foreach ($ source as $ vVal => $ vLabel ) {
603+ $ rolesList [] = ['value ' => $ vVal , 'label ' => $ vLabel ];
604+ }
638605
639- case 'string ' :
640- default :
641- $ filterFieldsContent .= '<input type="text" maxlength="255" id=" ' .$ htmlOptions ['id ' ].'" name=" ' .$ htmlOptions ['name ' ].'" class=" ' .$ htmlOptions ['class ' ].'" value=" ' .$ value .'" autocomplete="off" /> ' .PHP_EOL ;
642- break ;
606+ // Selected roles for milti-select
607+ $ role = [];
608+ if ( ! empty ($ value )) {
609+ if (is_string ($ value )) {
610+ $ value = explode (', ' , $ value );
611+ }
612+ $ values = array_filter ($ value );
613+ foreach ($ values as $ vLabel ) {
614+ if (isset ($ source [$ vLabel ])) {
615+ $ role [] = ['value ' => $ vLabel , 'label ' => $ source [$ vLabel ]];
616+ }
643617 }
618+ }
644619
645- $ filterFieldsContent .= ' </div > ' .PHP_EOL ;
646- $ filterFieldsContent .= ' </div> ' . PHP_EOL ;
620+ $ filterFieldsContent .= ' <vue-multiselect :id=" \'' . $ htmlOptions [ ' id ' ]. '\' " :options= \'' . json_encode ( $ rolesList ). '\' :values= \'' . json_encode ( $ role ). '\' :placeholder-text=" \' Select Role \' "></vue-multiselect > ' .PHP_EOL ;
621+ break ;
647622
648- $ count ++;
649- }
650- $ filterFieldsContent .= '</div> ' .PHP_EOL ;
651-
652- // $output .= $filterFieldsContent;
653- //
654- // $output .= '<div class="row">
655- // <div class="col">
656- // <div class="form-group">
657- // <div class="mt-1">
658- // <button type="submit" class="btn btn-primary btn-sm" name="search" data-remove-empties="true">
659- // <i class="fa fa-search-'.(!empty($filterFields['act']) && $filterFields['act'] === 'search' ? 'minus' : 'plus').' mr-1" aria-hidden="true"></i> Search
660- // </button>
661- // '.(!empty($filterFields['act']) && $filterFields['act'] === 'search' ? '<a class="btn btn-sm" href="'.self::getCancelRoute().'">Cancel</a>' : '').'
662- // </div>
663- // </div>
664- // </div>
665- // </div>
666- // </form>
667- // </div>
668- // </div>';
669- // return $output;
670-
671- // ===============================
623+ case 'string ' :
624+ default :
625+ $ filterFieldsContent .= '<input type="text" maxlength="255" id=" ' .$ htmlOptions ['id ' ].'" name=" ' .$ htmlOptions ['name ' ].'" class=" ' .$ htmlOptions ['class ' ].'" value=" ' .$ value .'" autocomplete="off" /> ' .PHP_EOL ;
626+ break ;
627+ }
628+
629+ $ filterFieldsContent .= '</div> ' .PHP_EOL ;
630+ $ filterFieldsContent .= '</div> ' .PHP_EOL ;
631+
632+ $ count ++;
633+ }
634+ $ filterFieldsContent .= '</div> ' .PHP_EOL ;
672635
673636 return view (
674637 'datagrid::filter ' ,
0 commit comments