post by heruprambadi on Oct 20, 2023

post by johnny on Oct 21, 2023

Hello @heruprambadi ,

I don’t understand what is your question to be honest. Would you like to trigger this event but for detailed/master form?

Regards
Johnny

post by heruprambadi on Oct 21, 2023

post by johnny on Oct 23, 2023

Hello @heruprambadi ,

You will need to:

  1. Enable the “publish_events” from configuration to true
  2. Use callbackAddField | Grocery CRUD - A PHP CRUD Generator Library and callbackEditField | Grocery CRUD - A PHP CRUD Generator Library for your input and make sure that the input
  3. Use the events ‘gcrud.form.add-load’ ‘gcrud.form.edit-load’. For example:
window.addEventListener('gcrud.form.add-load', ({detail}) => {
    // Your custom JavaScript here
});

I hope this helped.

Regards
Johnny

post by heruprambadi on Oct 23, 2023

Thx @johnny now i’m able to do it. I need this event “gcrud.form.add-load” to make it work.
I hope future GCE have feature like money input mask, because some user type 1.000.000, another user type 1,000,000, and the other type 1000000. We need to make standart for it.

For you who expriencing similar problem with me, i’m just gonna put it here, in case you need it.

callback add field in controller :

        $crud->callbackAddField('nama', function ($fieldType, $fieldName) {
            return '<input type="text" name ="nama" class = "myForm">';
        });

script in view file :

<script>
    window.addEventListener('gcrud.form.add-load', ({
        detail
    }) => {
        let input = document.getElementsByClassName("myForm");

        console.log(input.length);

        for (var i = 0; i < input.length; i++) {
            input[i].addEventListener("keyup", (e) => {
                formatCurrency(e.target);
            });
            input[i].addEventListener("keypress", (e) => {
                formatCurrency(e.target);
            });
        }

        function formatNumber(n) {
            // format number 1234567,89 to 1 234 567,89
            return n.replace(/\D/g, "").replace(/\B(?=(\d{3})+(?!\d))/g, ",")
        }

        function formatCurrency(input) {
            var input_val = input.value;
            if (input_val === "") {
                return;
            }
            var original_len = input_val.length;
            var caret_pos = input.selectionStart;
            input_val = formatNumber(input_val);
            input.value = input_val;
            var updated_len = input_val.length;
            caret_pos = updated_len - original_len + caret_pos;
            input.setSelectionRange(caret_pos, caret_pos);
        }
    });
</script>

post by heruprambadi on Oct 23, 2023

post by heruprambadi on Oct 23, 2023

post by johnny on Oct 26, 2023

post by johnny on Oct 28, 2023

Hello @heruprambadi ,

I confirm that this is a Grocery CRUD bug and this will be fixed for the next version.

I will keep you updated once the new version is released.

Regards
Johnny

post by heruprambadi on Oct 28, 2023

20 days later

post by johnny on Nov 18, 2023

post by heruprambadi on Nov 18, 2023

7 months later

post by heruprambadi on Jun 5, 2024

Hello @johnny , i confirm this not work with the latest version of GCE (V3.1.4). I just update my GCE using “composer update --prefer-dist” and my input mask not working anymore. I try to replace my GCE with the old one, and it working again. Any solution for this ?

post by johnny on Jun 8, 2024

Hello @heruprambadi that’s weird since I haven’t changed anything related with this change. Can you please check if publish_events configuration is set to true ? This will only work when this is true, the default configuration is false.

Regards
Johnny

post by heruprambadi on Jun 9, 2024

post by johnny on Jun 12, 2024

3 months later

post by johnny on Sep 12, 2024

1 / 17
Oct 2023