#php #laravel
Вопрос:
Я использую laravel 8 и пытаюсь сделать переключатели липкими с помощью шаблона blade, но перед тем, как мой javascript скажет, что это необходимо, даже если он проверен
Я попробовал это на радиовходе:
lt;label for="no" class="col form-check-label"gt;Nolt;/labelgt; {{ Form::radio('visualCheck', old('visualCheck') == "no", array('id'=gt;'yes', 'class="col')) }}
язык JavaScript:
let visualCheck = document.forms["form"]["visualCheck"].value; let visualCheckError = document.getElementById("visualCheckError"); ifValidate(visualCheck, visualCheckError, event); function errorStyler(errorSpan){ errorSpan.className = "col-6"; errorSpan.style.color = "#ff0000"; } function ifValidate(inputValue, inputError, event){ if (inputValue.length==0){ event.preventDefault(); inputError.innerHTML = "This field is required."; errorStyler(inputError); }
если я закомментирую javascript и использую внутреннюю проверку, тот же результат говорит, что это поле обязательно
контроллер:
public function compute(Request $request){ $rules = [ 'vessel' =gt; 'required', 'date' =gt; 'required', 'species' =gt; 'required', 'grade' =gt; 'required', 'temperature' =gt; 'required', 'visualCheck' =gt; 'required', 'skin' =gt; 'required', 'touch' =gt; 'required', 'damage' =gt; 'required', 'eyes' =gt; 'required', 'gills' =gt; 'required', 'gutting' =gt; 'required', 'washing' =gt; 'required', 'boxing' =gt; 'required', 'condition' =gt; 'required', 'checkedBy' =gt; 'required', ]; $validator = Validator::make($request-gt;all(), $rules); if ($validator-gt;fails()) { return redirect()-gt;back() -gt;withInput() -gt;withErrors($validator); } $finalTotal = ($request-gt;input("skin") $request-gt;input("touch") $request-gt;input("damage")) ($request-gt;input("eyes") $request-gt;input("gills") $request-gt;input("gutting")) ($request-gt;input("washing") $request-gt;input("boxing") $request-gt;input("condition")); $pointsAcheived = $finalTotal; $finalTotal = (string) $finalTotal; $percent = ($pointsAcheived / 27) * 100; $percent = number_format((float) $percent, 0, ".", ""); $percent = (string) $percent . "%"; $data = $request-gt;all(); try{ $report = new insertQualityReport(); $report-gt;vessel = $data["vessel"]; $report-gt;species = $data["species"]; $report-gt;grade = $data["grade"]; $report-gt;product_temperature = $data["temperature"]; $report-gt;visual_check = $data["visualCheck"]; $report-gt;skin = $data["skin"]; $report-gt;touch = $data["touch"]; $report-gt;damage = $data["damage"]; $report-gt;eyes = $data["eyes"]; $report-gt;gills = $data["gills"]; $report-gt;gutting = $data["gutting"]; $report-gt;washing = $data["washing"]; $report-gt;boxing = $data["boxing"]; $report-gt;conditions_of_fish_box = $data["condition"]; $report-gt;comments = $data["comments"]; $report-gt;checked_by = $data["checkedBy"]; $report-gt;intake_quantity = $data["intakeQuantity"]; $report-gt;rejected_quantity = $data["rejectedProduct"]; $report-gt;processed_quantity = $data["processed"]; $report-gt;date_recorded = $data["date"]; //$report-gt;created_at = date("h:i:s"); if (!empty($_POST["photo"])){ $report-gt;photo = $data["photo"]; } if (!$report-gt;save()) { return redirect()-gt;back() -gt;withInput() -gt;withErrors(["errors" =gt; ["Problem saving report"]]); } $report-gt;save(); return view('addqualityreport', compact('finalTotal', 'percent'))-gt;with('status', "Inserted Successfully!")-gt;with('data', $data); } catch (Exception $e) { return redirect()-gt;back() -gt;withInput() -gt;withErrors(["errors" =gt; [$e-gt;getMessage()]]); } }