Skip to main content
M.Hasanin
Inspiring
May 1, 2021
Answered

Trying to Disable/Enable Edittext field in UI but not Working!

  • May 1, 2021
  • 2 replies
  • 862 views

Hi Experts..

I'm trying hard to make edittext user input field to be disabled and enabled , it shouid be disable at first time until user interact with the UI and select the third radio button and it shouid be enabled! and i the user select another radio button it shouid be disabled but not working at all , here is my code (Part of Script UI) :

//Adding Page Number Group
var myPageNum = RadioPanel.add("group", undefined, {name: "myPageNum"});
myPageNum.preferredSize.width = 102;
myPageNum.orientation = "row";
myPageNum.alignChildren = ["right","right"];
myPageNum.spacing = 0;
myPageNum.margins =5; //Just Before Buttons
//myRadioGroup.orientation = "row";
myPageNum.add ("statictext", undefined, "Page Number:");
var myNum = myPageNum.add ("edittext", undefined, "5");
myNum.characters = 4;
//My edittext for PageNumbering is Disabled at first
myNum.enabled = false;

//Check if the typed is Number or not
myNum.onChange = checktext;
function checktext() { 
if (isNaN(Number(this.text))) {
alert("Are you Kidding! , Only numbers Accepted!");
myNum.text = ""
}
}

//Check For Enable or Disable Edittext field
radio3.onChange = checkradio3;
function checkradio3() { 
if (radio3.value == true)
if (myNum.enabled == false)
myNum.enabled = true;
else if  (radio3.value == false) {
myNum.enabled = false;
}
}

 also i tried direclty with if condition code :

if (radio3.value == true) {
myNum.enabled = true;
}
else if (radio3.value == false) {
myNum.enabled = false;
}

but no success!, every time i launch the script it will show (disabled edittext field) and if i try to select the third radio button (radio 3) nothing happened at all, please help and thanks in advance

Best

M.Hasanain

This topic has been closed for replies.
Correct answer brian_p_dts

Other good tips here, but this is another common design pattern. A simplified solution:

var input;
do {
   input = prompt("Enter a number");
} while(isNaN(input));

 

2 replies

rob day
Community Expert
Community Expert
May 1, 2021

Also, the ID dialog class has an enabling panel, and an integer input field, so you wouldn’t need listeners or a number test:

 

 

 


//result variables
var isEnabled, pNum;

makeDialog();

/**
* Construct the  dialog 
*/

function makeDialog(){
    var theDialog = app.dialogs.add({name:"Page Dialog", canCancel:true});
    with(theDialog){
        with(dialogColumns.add()){
            isEnabled = enablingGroups.add({checkedState:false, staticLabel:"Enter a Page Number:"})
            with(isEnabled){
                with(dialogColumns.add()){
                    staticTexts.add({staticLabel:"Page:"});
                }
                with(dialogColumns.add()){
                    pNum = integerEditboxes.add({editValue:1, minWidth:120});
                }
            }
        }
    }
	
    //the dialog results
    var res = theDialog.show();
    if(res == true){
        isEnabled = isEnabled.checkedState
        pNum = pNum.editValue;
        main()
	}else{
        theDialog.destroy();
    }
}


/**
* Run script.
* @Return void 
*/

function main(){
    alert("\nPanel Enabled = "+ isEnabled + "\nEntered number = " + pNum)
}




 

 

brian_p_dts
Community Expert
brian_p_dtsCommunity ExpertCorrect answer
Community Expert
May 1, 2021

Other good tips here, but this is another common design pattern. A simplified solution:

var input;
do {
   input = prompt("Enter a number");
} while(isNaN(input));

 

M.Hasanin
M.HasaninAuthor
Inspiring
May 1, 2021

Thanks Experts, I Figured the Problem my Self, i have to put Event listeners!

//This is Important so we Can Listen to user Selection
//Radio Event Listeners --------//Important to Let User Select Proper Radio--Radio 3 when Activated User Can Input
radio1.onClick = function (){
myNum.enabled = radio3.value;
}
radio2.onClick = function (){
myNum.enabled = radio3.value;
}

radio3.onClick = function (){
myNum.enabled = radio3.value;
}

 

Mohammad Hasanin
rob day
Community Expert
Community Expert
May 1, 2021

The integerEditbox only allows integers: