Page 1 of 1

Radio Button & Client Side Event

Posted: Fri Apr 12, 2024 7:48 pm
by kourosh

Hi
There is a problem with radio button and check box in "Client Side Event" (Phpmaker 2024) ,
Disabled Radio field in "Page_Load" or "Page_Render" Server Event doesn't enable in Client Side Event

Page_Load Server Event :
$this->"RadioField"->Disabled=true;


Client Side Event :

 "x_OtherField": { // keys = event types, values = handler functions
                "change": function(e) {
          
                       $(this).fields("RadioField").disabled(false);

    }
}

So I try any Jquery solution in Startup an client Script but it doesn't work.
Does anyone have a solution for this problem?


Re: Radio Button & Client Side Event

Posted: Fri Apr 12, 2024 8:50 pm
by arbei

kourosh wrote:

$this->"RadioField"->Disabled=true;

You have syntax error.

$(this).fields("RadioField").disabled(false);

.disabled() only set the "disabled" property of the input element, it will not work with radio button and checkbox list (with multiple radio buttons and checkboxes).


Re: Radio Button & Client Side Event

Posted: Sat Apr 13, 2024 12:04 am
by kourosh

Do you have any solution for this issue?


Re: Radio Button & Client Side Event

Posted: Sat Apr 13, 2024 10:13 am
by arbei

Your client side event should select all the radio buttons for the field and set the disabled attributes, see Inspect HTML element and add your own CSS styles on how to find the CSS selector.


Re: Radio Button & Client Side Event

Posted: Fri Apr 19, 2024 1:33 am
by kourosh

i used this code in 'Startup Script' and 'Client Script' and it didn't work.


$("#r_RadioField").removeAttr('disabled');
$("#r_RadioField").prop('disabled', false);

$("[id^='x_RadioField']").removeAttr('disabled');
$("[id^='x_RadioField']").prop('disabled', false);
--------------------------------
const checkbox = document.querySelector("[id^='x_CheckboxField']");
const RadioItems = document.querySelectorAll("input[type='radio'][id^='x_RadioField']");

checkbox.addEventListener("change", () => {
  RadioItems.forEach((item) => {
    item.disabled = !item.disabled;
  });
});

and so many jQuery Selector and Cammand....
I think main problem is use correct JQuery Selector for Radio Item Or Radio Group.


Re: Radio Button & Client Side Event

Posted: Fri Apr 19, 2024 9:18 am
by arbei

kourosh wrote:

const RadioItems = document.querySelectorAll("input[type='radio'][id^='x_RadioField']");

The id is not correct.

arbei wrote:

see Inspect HTML element and add your own CSS styles on how to find the CSS selector.


Re: Radio Button & Client Side Event

Posted: Sun Apr 21, 2024 6:59 pm
by kourosh

So phpmaker use Fieldname+RandomNumber for radiobox then I use [id^='x_RadioField'] to detect radiobox that start with x_name
I don't know what is suitable radio box field name.


Re: Radio Button & Client Side Event

Posted: Mon Apr 22, 2024 12:14 pm
by arbei

You may select based on the "data-target" attribute of the element. Again, see the HTML elements in your browser first. Also learn CSS Descendant combinator.