0

I have add more fields group for which I am using laravel-admin below code

    protected function form() {
        Admin::script('$("body").on("change", "#has-many-negotiations input[type=\"radio\"]", function() { console.log("s"); });');

            $form->hasMany('negotiations', function (Form\NestedForm $form) {
                $form->radio('comparative_statement', __('Comparative Statement'))->options(['1' => 'yes']);
                $form->file('file')->rules('required');
                $form->text('vendor')->rules('required');
                $form->text('initial')->rules('required');
                $form->text('intermediate_1');
                $form->text('intermediate_2');
                $form->text('intermediate_3');
                $form->text('final_no_regret')->rules('required');
                $form->select('awarded')->options(['No' => 'No', 'Yes' => 'Yes'])->rules('required');
            });
            

        return $form;
    }

Here it is creating radio buttons but I want only one radio button should be active one time

What I have tried.

As you can see I have tried to place a script that should call when any change happens to radio button

Also I have tried to add ->setAttribute('name') in the field but it does not support that

Also I have tried to add another below script but nothing is working

$(document).ready(function () {
    $('body').on('change', '#has-many-negotiations input[type="radio"]', function () {
        console.log("s");
        alert("SDafd");
        $(this).closest('.negotiations-set').find('input[type="radio"]').not(this).prop('checked', false);
    });
});
silentcoder
  • 992
  • 3
  • 9
  • 21
  • By default only one radio button is activate at a time. This is done by the browser already and just the way radio buttons work. Is that not working for you? You can create a runnable snippet here with the `<>` button. Just use the resulting HTML and jQuery code as your PHP code is probably not relevant for your core question here. – Peter Krebs Jul 25 '23 at 12:04
  • Yes, But names are not same because of the add more functionality created by `hasMany` as par `larave-admin` – silentcoder Jul 25 '23 at 12:05
  • Ah okay understood. In that case why not create a running example with HTML and some jQuery? You don't need the PHP part to demonstrate your problem. The `<>` snippet editor has an option to add jQuery as well in whichever version you need. – Peter Krebs Jul 25 '23 at 12:08
  • I just put that because it's not simple HTML/CSS and JS it is rendering by PHP code using `laravel-admin` package. So one who know how laravel-admin work can understand that much better. If it is simple HTML case it has already done. – silentcoder Jul 25 '23 at 12:18

0 Answers0