<commit_before><div class="col-md-6">
  <h2><%= t('new_defence_request') %></h2>

  <div class="search_box row-fluid">
    <%= bootstrap_form_tag(url: solicitors_search_defence_requests_path,  remote: true, class: 'solicitor_search') do |f| %>
      <%= label_tag 'q', t('search'), class: 'col-md-12' %>
      <div class='col-md-10'>
      <%= text_field_tag 'q', nil, placeholder: t('enter_solicitor_firm_name'), autocomplete: "off", class: 'form-control' %>
      </div>
      <%= f.submit 'Search', class: 'btn btn-primary col-md-2 pull-right' %>
    <% end %>
    <div class="list-group solicitor_results_list col-md-10">
    </div>
  </div>

  <%= bootstrap_form_for(@defence_request, class: 'new_defence_request') do |f| %>
    <%= render partial: 'shared/form_errors', locals: {object: @defence_request} %>

    <%= f.form_group :solicitor_type, label: { text: t('solicitor_type') } do %>
      <%= f.radio_button :solicitor_type, :duty, label: t('duty'), name: 'defence_request[solicitor_type]', inline: true, class: 'solicitor_type_radio', checked: true %>
      <%= f.radio_button :solicitor_type, :own, label: t('own'), name: 'defence_request[solicitor_type]', inline: true, class: 'solicitor_type_radio' %>
    <% end %>



    <!-- details -->
    <div class="panel panel-default details">
      <div class="panel-heading">
        <h3 class="panel-title"><%= t('details') %></h3>
      </div>
      <div class="panel-body">
        <%= f.text_field :solicitor_name, label: t('solicitor_name') %>
        <%= f.text_field :solicitor_firm, label: t('solicitor_firm') %>
        <%= f.select :scheme, DefenceRequest::SCHEMES, {label: t('scheme')} %>
        <%= f.text_field :phone_number, label: t('phone_number') %>
        <%= f.text_field :custody_number, label: t('custody_number') %>
        <%= f.text_field :allegations, label: t('allegations') %>
        <%= f.time_select :time_of_arrival, { label: t('time_of_arrival') }, { class: 'time-select' } %>
      </div>
    </div>
    <!-- detainee -->
    <div class="panel panel-default detainee">
      <div class="panel-heading">
        <h3 class="panel-title"><%= t('detainee') %></h3>
      </div>
      <div class="panel-body">
        <%= f.text_field :detainee_surname, label: t('detainee_surname') %>
        <%= f.text_field :detainee_first_name, label: t('detainee_first_name') %>

        <%= f.form_group :gender, label: {text: t('gender')} do %>
          <%= f.radio_button :gender, :male, label: t('male'), name: 'defence_request[gender]', inline: true %>
          <%= f.radio_button :gender, :female, label: t('female'), name: 'defence_request[gender]', inline: true %>
        <% end %>

        <%= f.check_box :adult, label: t('adult') %>

        <%= f.date_select :date_of_birth, {
          start_year: Date.today.year,
          end_year: 120.years.ago.year,
          label: t('date_of_birth')
        }, {
          class: 'time-select'
        } %>
      <%= f.check_box :appropriate_adult, label: t('appropriate_adult') %>
    </div>
  </div>
  <!-- comments -->
    <div class="panel panel-default comments">
      <div class="panel-heading">
        <h3 class="panel-title"><%= t('comments') %></h3>
      </div>
      <div class="panel-body">
        <%= f.text_area :comments, label: t('comments'), rows: '5' %>
      </div>
    </div>
    <%= f.form_group do %>
      <%= f.submit class: 'btn btn-primary' %>
    <% end %>
  <% end %>
</div>


<script>
 $(document).ready(function () {
   var ownSolicitor_checked = ($("input[type='radio']#defence_request_solicitor_type_own:checked").length > 0);

   var enable_form_fields_and_clear_search = function() {
     $('.solicitor_results_list').html("")
     $('input #q').val("")
     $('#defence_request_solicitor_firm').removeAttr("disabled");
     $('#defence_request_solicitor_name').removeAttr("disabled");
   }

   var disable_form_fields = function() {
     $('#defence_request_solicitor_firm').attr("disabled", "disabled");
     $('#defence_request_solicitor_firm').val("");
     $('#defence_request_solicitor_name').attr("disabled", "disabled");
     $('#defence_request_solicitor_name').val("");
   }

   if (ownSolicitor_checked){
     $('.search_box').show();
     enable_form_fields_and_clear_search();
     } else {
     $('.search_box').hide();
     disable_form_fields();
   }

   $(".solicitor_type_radio").change(function () {
     if (this.value == "own") {
       $('.search_box').stop(true,true).show(1000);
       enable_form_fields_and_clear_search();
     } else {
       $('.search_box').stop(true,true).hide(1000);
       disable_form_fields();
     }
   });

 });
</script>

<commit_msg>Clear form fields and search list when duty is selected<commit_after><div class="col-md-6">
  <h2><%= t('new_defence_request') %></h2>

  <div class="search_box row-fluid">
    <%= bootstrap_form_tag(url: solicitors_search_defence_requests_path,  remote: true, class: 'solicitor_search') do |f| %>
      <%= label_tag 'q', t('search'), class: 'col-md-12' %>
      <div class='col-md-10'>
      <%= text_field_tag 'q', nil, placeholder: t('enter_solicitor_firm_name'), autocomplete: "off", class: 'form-control' %>
      </div>
      <%= f.submit 'Search', class: 'btn btn-primary col-md-2 pull-right' %>
    <% end %>
    <div class="list-group solicitor_results_list col-md-10">
    </div>
  </div>

  <%= bootstrap_form_for(@defence_request, class: 'new_defence_request') do |f| %>
    <%= render partial: 'shared/form_errors', locals: {object: @defence_request} %>

    <%= f.form_group :solicitor_type, label: { text: t('solicitor_type') } do %>
      <%= f.radio_button :solicitor_type, :duty, label: t('duty'), name: 'defence_request[solicitor_type]', inline: true, class: 'solicitor_type_radio', checked: true %>
      <%= f.radio_button :solicitor_type, :own, label: t('own'), name: 'defence_request[solicitor_type]', inline: true, class: 'solicitor_type_radio' %>
    <% end %>



    <!-- details -->
    <div class="panel panel-default details">
      <div class="panel-heading">
        <h3 class="panel-title"><%= t('details') %></h3>
      </div>
      <div class="panel-body">
        <%= f.text_field :solicitor_name, label: t('solicitor_name') %>
        <%= f.text_field :solicitor_firm, label: t('solicitor_firm') %>
        <%= f.select :scheme, DefenceRequest::SCHEMES, {label: t('scheme')} %>
        <%= f.text_field :phone_number, label: t('phone_number') %>
        <%= f.text_field :custody_number, label: t('custody_number') %>
        <%= f.text_field :allegations, label: t('allegations') %>
        <%= f.time_select :time_of_arrival, { label: t('time_of_arrival') }, { class: 'time-select' } %>
      </div>
    </div>
    <!-- detainee -->
    <div class="panel panel-default detainee">
      <div class="panel-heading">
        <h3 class="panel-title"><%= t('detainee') %></h3>
      </div>
      <div class="panel-body">
        <%= f.text_field :detainee_surname, label: t('detainee_surname') %>
        <%= f.text_field :detainee_first_name, label: t('detainee_first_name') %>

        <%= f.form_group :gender, label: {text: t('gender')} do %>
          <%= f.radio_button :gender, :male, label: t('male'), name: 'defence_request[gender]', inline: true %>
          <%= f.radio_button :gender, :female, label: t('female'), name: 'defence_request[gender]', inline: true %>
        <% end %>

        <%= f.check_box :adult, label: t('adult') %>

        <%= f.date_select :date_of_birth, {
          start_year: Date.today.year,
          end_year: 120.years.ago.year,
          label: t('date_of_birth')
        }, {
          class: 'time-select'
        } %>
      <%= f.check_box :appropriate_adult, label: t('appropriate_adult') %>
    </div>
  </div>
  <!-- comments -->
    <div class="panel panel-default comments">
      <div class="panel-heading">
        <h3 class="panel-title"><%= t('comments') %></h3>
      </div>
      <div class="panel-body">
        <%= f.text_area :comments, label: t('comments'), rows: '5' %>
      </div>
    </div>
    <%= f.form_group do %>
      <%= f.submit class: 'btn btn-primary' %>
    <% end %>
  <% end %>
</div>


<script>
 $(document).ready(function () {
   var ownSolicitor_checked = ($("input[type='radio']#defence_request_solicitor_type_own:checked").length > 0);

   var enable_form_fields = function() {
     $('#defence_request_solicitor_firm').removeAttr("disabled");
     $('#defence_request_solicitor_name').removeAttr("disabled");
   }

   var disable_form_fields_and_clear_search = function() {
     $('#defence_request_solicitor_firm').attr("disabled", "disabled");
     $('#defence_request_solicitor_firm').val("");
     $('#defence_request_solicitor_name').attr("disabled", "disabled");
     $('#defence_request_solicitor_name').val("");
     $('.solicitor_results_list').html("")
     $('#q').val("")
   }

   if (ownSolicitor_checked){
     $('.search_box').show();
     enable_form_fields();
     } else {
     $('.search_box').hide();
     disable_form_fields_and_clear_search();
   }

   $(".solicitor_type_radio").change(function () {
     if (this.value == "own") {
       $('.search_box').stop(true,true).show(1000);
       enable_form_fields();
     } else {
       $('.search_box').stop(true,true).hide(1000);
       disable_form_fields_and_clear_search();
     }
   });

 });
</script>


{'fraction_non_alphanumeric': 0.19764957264957264, 'fraction_numerical': 0.006196581196581196, 'mean_word_length': 3.4093264248704664, 'pattern_counts': {'":': 0, '<': 153, '<?xml version=': 0, '>': 155, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '961404', 'n_tokens_mistral': 3465, 'n_tokens_neox': 3214, 'n_words': 556}