Radio Box Not Selected State

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

Radio Box Not Selected State

Post by michaelmcewen »

Ok, I have a Radio Box that's basically a Yes/No selector (1/0). If I have it "required" then it must have a 1 (Yes) value. If it has a 0 (No) value, it treats it as if it wasn't set.

Now, what I need is a third state. I need to know if they have not selected Yes or No, I want to require that they select one of them, and if they haven't, then I would give an error message about it being required. Now, normally I would use the NULL value to do this, but I'm not sure how this works in PHPMaker. Do I need to set the field with ENUM and 3 values? Perhaps 0,1,2 where 0 (default) would be "not selected" and then 1=Yes and 2=No?


sangnandar
User
Posts: 980

Post by sangnandar »

You can use Row_Inserting/Row_Updating server event (search this forum for those events, there are plenty).

In brief it will goes like this:

  • Check input value
  • If value != 1, throw error message.

michaelmcewen
User
Posts: 78

Post by michaelmcewen »

That's not what I need. That's what it is doing right now.
The possible "states" are

  1. not selected
  2. Yes
  3. No

The radio box needs to be "Yes" and "No" but I need to be able to detect if they haven't clicked on yes or no yet.


kirondedshem
User
Posts: 642

Post by kirondedshem »

Am not sure but A radio button is by default a true/false, yes/no type of control basically a boolean control, so by default its only able to hold yes or no where by default no = not selecting it.

SO if you require another state ie "not selected" then it cant accommodate.I suggest you move to either:
1.a select control(drop down), wehere you can adda user defined list of yes and no, hence it will always be empty when not yes or no.

  1. a checkbox you can also set it up the same way as a drop down, but it ives a much better feel or yes and no, and it will still be empty when not yes or no.

Both these can be stored as strings or defined in enum('yes','no') in mysql.

You can also add "not selected" as an option to choose from in this case as well if you need to.


sangnandar
User
Posts: 980

Post by sangnandar »

Your not-selected is neither a state nor "state". It's not-a-state.
It will defy any logic If you try to get a state of a not-a-state. It's the same as trying to get number from a NaN (javascript).

michaelmcewen wrote:
The possible "states" are

  1. not selected
  2. Yes
  3. No
    If you define not-selected as a state then it isn't not-a-state anymore. It will behave exactly the same as Yes or No.

michaelmcewen wrote:
The radio box needs to be "Yes" and "No" but I need to be able to detect if they
haven't clicked on yes or no yet.
Then you want to run a not-a-state condition against, now a well defined state, not-selected state.

For further discussion please post your code.


mobhar
User
Posts: 11660

Post by mobhar »

michaelmcewen wrote:
but I need to be able to detect if they haven't clicked on yes or no yet.

  1. Just enable "Required" from "Fields" setup -> "Edit Tag" pane,
  2. Make sure you did not setup any value in "Default Value" from "Fields" setup -> "Add Page",
  3. Re-generate ALL the script files again.

michaelmcewen
User
Posts: 78

Post by michaelmcewen »

Actually, you're describing a checkbox...the radio box is the one that can have multiple answers...the checkbox is the one that is binary.

Not selected is a state, normally it is null (in regular programming, not web), and I use it all the time.

Mobhar, I'll give that a go...I do believe I've set a default value, so I'll remove that and see what happens.

Thanks!


Post Reply