cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
ehchandlerjr
Level V

Enable and disable a button box based on input.

So I have a button box in a modal window, with two column selection boxes above it. The math later on could break if the two columns are the same, so I don't want the user to be able to click the same columns. I assume the simplest way to do this is to disable the button box until conditions are satisfied (both column selector boxes have a selection and don't have the same (assuming there are more than 1, which now that I think about it, I'll have to deal with that too. gah)). Anyway, I've tried to get the enable thing not working, following a staff member's suggestion here, but its not working and just continues on through the code. I'm assuming its because the enable isn't live, but I'm not sure why the staff member's code worked in the link I put above. What am I doing wrong?

New Window("Select Variables", << Type("Modal Dialog"),
    H List Box(
        V List Box(
            Text Box("Select Major Variable"),
            lbMajor = List Box(combinedCols, <<Set Max Selected(1))
        ),
        V List Box(
            Text Box("Select Minor Variable"),
            lbMinor = List Box(combinedCols, <<Set Max Selected(1))
        )
    ),
    H List Box(
        okButton = Button Box("OK", If(majorVar != {} & minorVar != {} & majorVar != minorVar,
			<< Enable(1), << Enable(0)),
            majorVar = lbMajor << Get Selected;
            minorVar = lbMinor << Get Selected;
            If(majorVar != {} & minorVar != {} & majorVar != minorVar,
                Print("Processing with major: " || Char(majorVar) || ", minor: " || Char(minorVar));
                Window("Select Variables") << Close Window;
            ,
                Beep(); // Optional: Add a beep sound for alert
                Show("Please select different major and minor variables.");
            )
        ),
        Button Box("Cancel", Window("Select Variables") << Close Window; Throw("!Canceled Graph Building")
		)
	)
);

 

Edward Hamer Chandler, Jr.
1 ACCEPTED SOLUTION

Accepted Solutions
ErraticAttack
Level VI

Re: Enable and disable a button box based on input.

You might try something like this.

 

Note that if you're not using JMP17 or newer it might not work properly

 

combinedCols = {"A","B","C"};

New Window("Select Variables", << Type("Modal Dialog"),
	<<On Validate(
		window:validated
	)
,
	window:enable function = Function( {},
		{Default Local},
		majorVar = window:lbMajor << Get Selected;
		minorVar = window:lbMinor << Get Selected;
		If( N Items( majorVar ) & N Items( minorVar ) & majorVar != minorVar,
			window:validated = 1
		,
			window:validated = 0
		);
		window:ok button << Enable( window:validated )
	);
    H List Box(
        V List Box(
            Text Box("Select Major Variable"),
            window:lbMajor = List Box(combinedCols, <<Set Max Selected(1), enable function )
        ),
        V List Box(
            Text Box("Select Minor Variable"),
            window:lbMinor = List Box(combinedCols, <<Set Max Selected(1), enable function)
        )
    ),
    H List Box(
        window:ok button = Button Box("OK", 
			majorVar = window:lbMajor << Get Selected;
			minorVar = window:lbMinor << Get Selected;
			If( N Items( majorVar ) & N Items( minorVar ) & majorVar != minorVar,
				window:validated = 1
			,
				window:validated = 0
			);
            If( window:validated,
                Print("Processing with major: " || Char(majorVar) || ", minor: " || Char(minorVar));
                Window("Select Variables") << Close Window;
            ,
                Beep(); // Optional: Add a beep sound for alert
                Show("Invalid Selection");
                {window:lbMajor, window:lbMinor} << Select; window:lbMajor << Inval << Update Window;
                Wait( 0.25 );
                {window:lbMajor, window:lbMinor} << DeSelect; window:lbMajor << Inval << Update Window;
                Wait( 0.25 );
                {window:lbMajor, window:lbMinor} << Select; window:lbMajor << Inval << Update Window;
                Wait( 0.25 );
                {window:lbMajor, window:lbMinor} << DeSelect; window:lbMajor << Inval << Update Window;
            )
        ,
			<<Enable( 0 )
        )
    ,
        Button Box("Cancel", Throw("!Canceled Graph Building") )
	)
);
Jordan

View solution in original post

2 REPLIES 2
ErraticAttack
Level VI

Re: Enable and disable a button box based on input.

You might try something like this.

 

Note that if you're not using JMP17 or newer it might not work properly

 

combinedCols = {"A","B","C"};

New Window("Select Variables", << Type("Modal Dialog"),
	<<On Validate(
		window:validated
	)
,
	window:enable function = Function( {},
		{Default Local},
		majorVar = window:lbMajor << Get Selected;
		minorVar = window:lbMinor << Get Selected;
		If( N Items( majorVar ) & N Items( minorVar ) & majorVar != minorVar,
			window:validated = 1
		,
			window:validated = 0
		);
		window:ok button << Enable( window:validated )
	);
    H List Box(
        V List Box(
            Text Box("Select Major Variable"),
            window:lbMajor = List Box(combinedCols, <<Set Max Selected(1), enable function )
        ),
        V List Box(
            Text Box("Select Minor Variable"),
            window:lbMinor = List Box(combinedCols, <<Set Max Selected(1), enable function)
        )
    ),
    H List Box(
        window:ok button = Button Box("OK", 
			majorVar = window:lbMajor << Get Selected;
			minorVar = window:lbMinor << Get Selected;
			If( N Items( majorVar ) & N Items( minorVar ) & majorVar != minorVar,
				window:validated = 1
			,
				window:validated = 0
			);
            If( window:validated,
                Print("Processing with major: " || Char(majorVar) || ", minor: " || Char(minorVar));
                Window("Select Variables") << Close Window;
            ,
                Beep(); // Optional: Add a beep sound for alert
                Show("Invalid Selection");
                {window:lbMajor, window:lbMinor} << Select; window:lbMajor << Inval << Update Window;
                Wait( 0.25 );
                {window:lbMajor, window:lbMinor} << DeSelect; window:lbMajor << Inval << Update Window;
                Wait( 0.25 );
                {window:lbMajor, window:lbMinor} << Select; window:lbMajor << Inval << Update Window;
                Wait( 0.25 );
                {window:lbMajor, window:lbMinor} << DeSelect; window:lbMajor << Inval << Update Window;
            )
        ,
			<<Enable( 0 )
        )
    ,
        Button Box("Cancel", Throw("!Canceled Graph Building") )
	)
);
Jordan
ehchandlerjr
Level V

Re: Enable and disable a button box based on input.

Wow! I didn't even have to edit it. Way more than I expected. And somehow I had missed that you could reference things within windows the same way you reference tables and their children. Thanks for a great answer. I really appreciate it.

Edward Hamer Chandler, Jr.