lundi 30 décembre 2019

the required field change to red

help me on required field that suppose to change color when empty like this:

enter image description here

the dropdown on course_id and grade_id should change to red when the required field appear after the submit the form.

this is the form i use to create the form for past education.

form_modal.blade.php:


    <div class="form-group required">
        <label class="col-lg-2 control-label"></label>
        <div class="col-lg-4">
            {!! Form::dropdown('institution_id', $institution, @$pasteducationinfo['institution_id'],'class="select2-form institution_id"') !!}
        </div>
    </div>
    <div id="institution" class="form-group hide">
        <label class="col-lg-2 control-label"></label>
        <div class="col-lg-4">
            <input type="text" name="institution_name" class="form-control" value="" placeholder="SMK Cyberjaya">
        </div>
    </div>
    @if(!empty($edulevelinfo['is_course_able']))
    <div class="table-responsive repeater">
        <table id="courseassessmentnew-table" class="table table-striped b-t b-b" data-repeater-list="pasteducation">
            <thead>
                <th>{!! msg('lbl_course') !!}</th>
                <th>{!! msg('lbl_grade') !!}</th>
                <th></th>
            </thead>
            <tbody>
            @if(!empty($pasteducationdetailinfo))
                @foreach($pasteducationdetailinfo as $detailinfo)
                    @if (!empty($detailinfo->educationCourse->is_mandatory))
                        <tr>
                            <td>
                                {!! $educourseselection[$detailinfo['course_id']] !!}
                                <input type="hidden" name="course_id[]" value="">
                            </td>
                            <td>
                                {!! Form::dropdown('grade_id[]', $gradeselection, $detailinfo['grade_id'],'class="select2-form"') !!}
                            </td>
                            <td></td>
                        </tr>
                    @else
                        <tr data-repeater-item>
                            <td>
                                {!! Form::dropdown('course_id', $mandeducationcourse, $detailinfo['course_id'],'class="select2-form past-education-course"') !!}
                            </td>
                            <td>
                                {!! Form::dropdown('grade_id', $gradeselection, $detailinfo['grade_id'],'class="select2-form"') !!}
                            </td>
                            <td>
                                <span data-repeater-delete="" class="btn btn-danger">
                                    <i class="glyphicon glyphicon-remove" ></i>
                                </span>
                            </td>
                        </tr>
                    @endif
                @endforeach
                <tr data-repeater-item>
                    <td>
                        {!! Form::dropdown('course_id', $educourse, '','class="select2-form past-education-course" required') !!}
                    </td>
                    <td>
                        {!! Form::dropdown('grade_id', $gradeselection, '','class="select2-form" required') !!}
                    </td>
                    <td>
                        <span data-repeater-delete="" class="btn btn-danger">
                            <i class="glyphicon glyphicon-remove" ></i>
                        </span>
                    </td>
                </tr>
            @else <?php //display field for new application ?>
                @if ($mandeducourseselection->count() > 0)
                    @foreach ($mandeducourseselection as $item)
                    <tr>
                        <td>
                        {!! $item->name !!}
                            <input type="hidden" name="course_id[]" value="">
                        </td>
                        <td>
                            {!! Form::dropdown('grade_id[]', $gradeselection, '','class="select2-form" required') !!}
                        </td>
                    </tr>
                    @endforeach
                @endif
                <tr data-repeater-item>
                    <td>
                        {!! Form::dropdown('course_id', $educourseselection, '','class="select2-form past-education-course" required') !!}
                    </td>
                    <td>
                        {!! Form::dropdown('grade_id', $gradeselection, '','class="select2-form" required') !!}
                    </td>
                    <td>
                        <span class="btn btn-danger" onClick="removerow(this)">
                            <i class="glyphicon glyphicon-remove" ></i>
                        </span>
                    </td>
                </tr>
            @endif
            </tbody>
            <tr>
                <td colspan="2"></td>
                <td>
                    <span data-repeater-create="" class="btn btn-success btn-md">
                        <i class="glyphicon glyphicon-plus"></i>
                    </span>
                </td>
            </tr>
        </table>
    </div>
    @endif
</div>
<input type="hidden" name="student_id" value="" />
<input type="hidden" name="past_education_id" value="" />
<input type="hidden" name="education_level_id" value="" />
<!-- /content -->

{!! JsValidator::formRequest('App\Http\Requests\Student\PastEducationRequest', '#form-education' ); !!}

the next file is a request file that i use to do the checking of mandatory field. pasteducationrequest.php:

<?php

namespace App\Http\Requests\Student;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Request;

class PastEducationRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'education_level_id'         => 'required',
            'institution_id'             => 'required',
            'pasteducation.0'            => 'required|sometimes',
            'pasteducation.1'            => 'required|sometimes',
            'pasteducation.2'            => 'required|sometimes',
            'pasteducation.3'            => 'required|sometimes',
            'pasteducation.4'            => 'required|sometimes',
            'pasteducation.5'            => 'required|sometimes',
            'pasteducation.6'            => 'required|sometimes',
            'pasteducation.7'            => 'required|sometimes',
            'pasteducation.8'            => 'required|sometimes',
            'pasteducation.9'            => 'required|sometimes',
            'pasteducation.10'           => 'required|sometimes',
            'pasteducation.11'           => 'required|sometimes',
            'pasteducation.12'           => 'required|sometimes',
            'pasteducation.13'           => 'required|sometimes',
            'pasteducation.14'           => 'required|sometimes',
            'pasteducation.15'           => 'required|sometimes',
            'pasteducation.16'           => 'required|sometimes',
            'pasteducation.17'           => 'required|sometimes',
            'pasteducation.18'           => 'required|sometimes',
            'pasteducation.19'           => 'required|sometimes',
            'pasteducation.0[course_id]' => 'required',
        ];
    }
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire