z-song / laravel-admin

Build a full-featured administrative interface in ten minutes
https://laravel-admin.org
MIT License
11.12k stars 2.81k forks source link

radio add more functionality on click not working #5803

Closed urfusion closed 1 year ago

urfusion commented 1 year ago

Description: not able to add name on radio button to make only one select at a time for dynamic field

Steps To Reproduce:

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;
}

Also I have tried to add script in bootstrap.php file by using Admin::js('/packages/admin/js/main.js');

below is the code

$(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);
    });
});
Yanghsuanming commented 1 year ago
        $triChange = <<<EOF
        (function(){
            $('body').on('ifChecked', "input[name*='[comparative_statement][]']", function(){
                $("input[name*='[comparative_statement][]']").prop('checked', false).iCheck('update');
            })
        })();
        EOF;

        Admin::script(
            $triChange
        );