Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

102
Views
Label Add Class

I have two selected dropdown which the second dropdown is controlled by the first. It goes by this:

First dropdown:

<x-forms.select id="trees" label="Tree" wire:model.defer="tree" required>
    <x-slot name="option">
        @foreach($trees as $item)
            <option value="{{$item->id}}">{{ __(strtoupper($item->name))}}</option>
         @endforeach
     </x-slot>
 </x-forms.select>

Second dropdown

<x-forms.select id="fruits" label="Fruits" wire:model="fruit> </x-forms.select>

The x-forms.select is from assets/components

<div class="@error($attributes->wire('model')->value()) has-error @enderror ">
    <div  @isset($label) class="form-group" @endisset wire:ignore>
        @isset($label)
           <label class="control-label ">{{ $label ?? 'Select' }}</label>@if(isset($required))<span style="color: red">*</span>@endif
        @endisset

//and so on

So my question is how to make second label set 'required' (span added) from @if(isset($required))*@endif in the assets when the first dropdown is chosen.

I have tried

const targetLabel = $('#fruits').prev('label');
targetLabel.addClass('required');

 $('label[for="#fruits"]').append('<span style="color: red">*</span>');

 $('label[for="#fruits"]').addClass('required');

 $('#fruits').addClass('required');

 $('#fruits').next('label').append('<span style="color: red">*</span>');

I had done the logic when selected. So the remain is to add the 'required' class. Thank you

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!