Yes/No Attribute can not be switched to OFF if required

If you think that something doesn't work in Aware IM post your message here
Post Reply
BobK
Posts: 544
Joined: Thu Jan 31, 2008 2:14 pm
Location: Cincinnati, Ohio, USA

Yes/No Attribute can not be switched to OFF if required

Post by BobK »

I have a Required attribute with Type 'Yes/No' and an initial value of 'Yes' that uses the Switch widget.

If I move the Switch to 'OFF' I get the 'This field is required' error.

Using the Checkbox widget works as expected, but I would really like to use the Switch widget.

Anyone else experience this?

By the way, I am using the latest build (2628)
Bob
PointsWell
Posts: 1457
Joined: Tue Jan 24, 2017 5:51 am
Location: 'Stralya

Re: Yes/No Attribute can not be switched to OFF if required

Post by PointsWell »

BobK wrote:I have a Required attribute with Type 'Yes/No' and an initial value of 'Yes' that uses the Switch widget.

If I move the Switch to 'OFF' I get the 'This field is required' error.

Using the Checkbox widget works as expected, but I would really like to use the Switch widget.

Anyone else experience this?

By the way, I am using the latest build (2628)
Logically how would you make a switch mandatory? It defaults to the Off position until you save the form and then that becomes No/Zero/Off (I think). The switch can't be in a NULL position, it is always in a default position so how would you test that it had been completed.
idpSteve
Posts: 201
Joined: Thu Jul 27, 2017 6:13 am
Location: Johannesburg, South Africa
Contact:

Re: Yes/No Attribute can not be switched to OFF if required

Post by idpSteve »

Have you tried setting initial value to 'No'?

If you set to 'On'/'Yes' and save the form, then edit the object and change it to 'Off'/'No' do you still get the error?
BobK
Posts: 544
Joined: Thu Jan 31, 2008 2:14 pm
Location: Cincinnati, Ohio, USA

Re: Yes/No Attribute can not be switched to OFF if required

Post by BobK »

Further testing using MySQL (if that matters)

Tested 4 fields, all with type 'Yes/No' and the Switch widget

Field1 is required with initial value of 'No'
Field2 is required with initial value of 'Yes'
Field3 is not required with no initial value
Field4 is required with no initial value

When creating a record, Field1 and Field4 receive 'This field is required' error
I can only create a record if Field1, Field2 and Field4 are all set to 'Yes'
PointsWell is correct, Field3 defaults to 'No' and i saved in the database as '0'.

When updating an existing record, changing Field1, Field2 or Field4 to 'No' receives the 'This field is required' error

Since it appears that a 'Yes/No' attribute using the Switch widget can never be null (as PointsWell pointed out) I can safely remove the 'Required' property.
On the other hand, since the field can never be null, even if it is required, I should never see the 'This field is required' error. But I do.
Bob
rocketman
Posts: 1239
Joined: Fri Jan 02, 2009 11:22 pm
Location: Preston UK
Contact:

Re: Yes/No Attribute can not be switched to OFF if required

Post by rocketman »

AwareIM yes/no fields alway used to have 3 states (i'm on 8.1 so not sure if this is still relevant )
yes - 1
no - 0
and empty or null (nothing)

Just out of curiosity, could you try saving a new record whilst the state is ON then editing it and turning it OFF to see if it sticks

If it does, then a BO rule might help something like IF YESNOAttribute is UNDEFINED then YESNOAttribute='No'
Rocketman

V8.7 Developer Edition. Server 2016 Standard edition. MySql 5.5
rocketman
Posts: 1239
Joined: Fri Jan 02, 2009 11:22 pm
Location: Preston UK
Contact:

Re: Yes/No Attribute can not be switched to OFF if required

Post by rocketman »

“PointsWell is correct, Field3 defaults to 'No' and i saved in the database as '0'.”

Are you sure about this? Since the field is “not require” I’d bet it defaulted to null (empty) and you saved it as that
Rocketman

V8.7 Developer Edition. Server 2016 Standard edition. MySql 5.5
PointsWell
Posts: 1457
Joined: Tue Jan 24, 2017 5:51 am
Location: 'Stralya

Re: Yes/No Attribute can not be switched to OFF if required

Post by PointsWell »

rocketman wrote:“PointsWell is correct, Field3 defaults to 'No' and i saved in the database as '0'.”

Are you sure about this? Since the field is “not require” I’d bet it defaulted to null (empty) and you saved it as that
On BO creation it may be NULL. On save the switch when the it is in the No position then it saves as 0. The switch can only be on or off yes or no when the BO is saved, there is no third position. This is a binary field after all so programmatically it can only be 1 or 0 to maintain the binary concept, setting it to NULL indicates that the options you are trying to capture are not in fact binary.

If you are creating the BO by process and never show the form you can circumvent this and it will save as NULL if you don't have a default value and your process doesn't set the value. You might be able to get the checkbox to not save as 0 but it it does I'd say that is a bug - I haven't tested and tend not to use checkboxes in my binary choices.

Given the behaviour and applying some logic the required flag seems to be covering those instances such as "I have read the T&Cs" where you must insist that the field is checked before progressing. It is fairly difficult to see how else to implement required value with a field that is yes or no (the NULL being only a temporary state existing only when an object is not used via the UI and not possible to return to with the UI without a process to remove the value)
rocketman
Posts: 1239
Joined: Fri Jan 02, 2009 11:22 pm
Location: Preston UK
Contact:

Re: Yes/No Attribute can not be switched to OFF if required

Post by rocketman »

Pointswell - you're right, my apologies. I made a small BSV and tested. Curious as to why AIM should consider 0 (No) as not fulfilling the "Required" requirement . Anyway, as long as an initial value is set to something and the "Required" is left unchecked, BobK will achieve his desired result

With your logic requirements, I have a similar requirement for T's and C's. I set the initial value to "No" and then put a rule in place IF NOT(YESNOattribute='Yes') then REPORT ERROR 'You have not indicated that you have read the T's And C's

In the UK, we are not allowed to set the defaults to 'Yes'
Rocketman

V8.7 Developer Edition. Server 2016 Standard edition. MySql 5.5
PointsWell
Posts: 1457
Joined: Tue Jan 24, 2017 5:51 am
Location: 'Stralya

Re: Yes/No Attribute can not be switched to OFF if required

Post by PointsWell »

rocketman wrote:Curious as to why AIM should consider 0 (No) as not fulfilling the "Required" requirement .
Because if you conform to binary being either 1 or 0 (ie you have correctly given the field an initial value) then which answer is the field in a "completed" state? It can only be 1/yes.
rocketman
Posts: 1239
Joined: Fri Jan 02, 2009 11:22 pm
Location: Preston UK
Contact:

Re: Yes/No Attribute can not be switched to OFF if required

Post by rocketman »

Not that it makes the slightest bit of difference here but I don't agree with you last argument. If I have an attribute with a choice list which is set as "required", I would expect the "required" to be fulfilled if any one item in the choice list is entered. A binary field should be no different - it is a choice list of yes or no and either option should fulfil the "required" option.

The "Required" option on a binary is however superfluous since it cannot be empty
Rocketman

V8.7 Developer Edition. Server 2016 Standard edition. MySql 5.5
BobK
Posts: 544
Joined: Thu Jan 31, 2008 2:14 pm
Location: Cincinnati, Ohio, USA

Re: Yes/No Attribute can not be switched to OFF if required

Post by BobK »

Even more testing:

I changed the widget for all 4 of my test attributes from Switch to CheckBox and retested.

Just like my testing using the Switch widget:
Field1 is required with initial value of 'No'
Field2 is required with initial value of 'Yes'
Field3 is not required with no initial value
Field4 is required with no initial value

When creating a record, I do not get any errors and Field2 is saved in the DB as '1' (Yes/On) and all the other fields are saved in the DB as '0' (No/Off)
I can update all the fields to Yes and save with no errors and update all the fields to No and save with no problems.
I only get the "Required" error when using the Switch widget and the attribute is set to Required and has a value of 'Off'


I agree with rocketman's final statements:
Not that it makes the slightest bit of difference here but I don't agree with you last argument. If I have an attribute with a choice list which is set as "required", I would expect the "required" to be fulfilled if any one item in the choice list is entered. A binary field should be no different - it is a choice list of yes or no and either option should fulfil the "required" option.

The "Required" option on a binary is however superfluous since it cannot be empty
And to set the record straight, I have un-checked the Required option for all my Yes/No attributes.
Bob
Post Reply