Radio Button & Client Side Event

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
kourosh
User
Posts: 8

Radio Button & Client Side Event

Post 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?


arbei
User
Posts: 9390

Post 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).


kourosh
User
Posts: 8

Post by kourosh »

Do you have any solution for this issue?


arbei
User
Posts: 9390

Post 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.


kourosh
User
Posts: 8

Post 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.


arbei
User
Posts: 9390

Post 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.


kourosh
User
Posts: 8

Post 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.


arbei
User
Posts: 9390

Post 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.


Post Reply