Controlling ActiveForm Field Requirement From Client Side

I have a form with fields that will be dependent and I need to be able to enable / disable the form validation requirement status for these from the client side. Please disregard possible model rules. Suffice it to say that I need a client side jQuery / javascript solution.

Let’s say I have the following field:


<form id="user-form" action="/admin/user/create" method="post">

  <div class="form-group field-user-username required">

      <label class="control-label" for="user-username">Username</label>

     <input id="user-username" class="form-control" name="User[username]" maxlength="16" type="text">

      <div class="help-block"></div>

  </div>

</form>

By default it is required. Based on some trigger, I want to say that this field is NOT required so that the client side validation won’t flag it. I do not want to turn off client side validation, unless it is the only option. I don’t want to do something drastic like deleting it from the DOM.

I tried setting it as ‘disabled’, but it did not work. I tried hidding the field, that did not work.

Is there something built into yii.validation.js or yii.activeForm.js that will do what I need? If so, please provide a working example.