Yii2: How to disable radio button

<?php  echo $form->field($model, 'status')->radioButtonGroup($model->getStatusList(), ['disabledItems'=>['APPROVED','DIGITAL','CDP']], 
    [
    'class' => 'btn-group-sm',
    'itemOptions' => ['labelOptions' => ['class' => 'btn btn-warning']]
    ]); 
    ?>

enter image description here

I want to disable all previous radio buttons from currently checked. As I showed in image status 'APPROVED','DIGITAL','CDP' are disabled because status print is selected. I have put these three status in disabled function but how to achieve this using jQuery.

PS- Using Yii2

HTML Code-

<div class="form-group field-status-status required">
    <label class="control-label" for="status-status">Status</label>
    <input type="hidden" name="Status[status]" value="">
    <div id="status-status" class="btn-group" data-toggle="buttons">
        <label class="btn btn-default disabled">
            <input type="radio" name="Status[status]" value="APPROVED" disabled> Approved</label>
        <label class="btn btn-default disabled">
            <input type="radio" name="Status[status]" value="DIGITAL" disabled> Digital</label>
        <label class="btn btn-default disabled">
            <input type="radio" name="Status[status]" value="CDP" disabled> CDP</label>
        <label class="btn btn-default">
            <input type="radio" name="Status[status]" value="PRINT"> Print</label>
        <label class="btn btn-default">
            <input type="radio" name="Status[status]" value="OTHERPROCESS"> OtherProcess</label>
        <label class="btn btn-default">
            <input type="radio" name="Status[status]" value="PACKING"> Packing</label>
        <label class="btn btn-default">
            <input type="radio" name="Status[status]" value="DISPATCH"> Dispatch</label>
    </div>

Answers:

Answer

You can use prop to disable radio buttons.

$(':radio:checked').closest('label').prevAll('label :radio').prop('disabled', true);

Demo:

$(':radio').on('change', function() {
  $(':radio:checked').closest('label').prevAll('label').addClass('disabled').children(':radio').prop('disabled', true);
}).trigger('change');
.disabled {
  color: gray;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<div class="form-group field-status-status required">
  <label class="control-label" for="status-status">Status</label>
  <input type="hidden" name="Status[status]" value="">
  <div id="status-status" class="btn-group" data-toggle="buttons">
    <label class="btn btn-default">
      <input type="radio" name="Status[status]" value="APPROVED">Approved</label>
    <label class="btn btn-default">
      <input type="radio" name="Status[status]" value="DIGITAL">Digital</label>
    <label class="btn btn-default">
      <input type="radio" name="Status[status]" value="CDP" checked>CDP</label>
    <label class="btn btn-default">
      <input type="radio" name="Status[status]" value="PRINT">Print</label>
    <label class="btn btn-default">
      <input type="radio" name="Status[status]" value="OTHERPROCESS">OtherProcess</label>
    <label class="btn btn-default">
      <input type="radio" name="Status[status]" value="PACKING">Packing</label>
    <label class="btn btn-default">
      <input type="radio" name="Status[status]" value="DISPATCH">Dispatch</label>
  </div>

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.