View Single Post
Old 04-10-2022, 05:29 AM   #369
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,469
Karma: 8025600
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
Question: I swapped a bool column to a psuedobool composite returning yes/no. This broke existing check_yes_nos. What's the best option to replace it?

$#column == 'Yes' is what I'm using for now.

edit: I am curious as to whether check_yes_no could be extended to bool columns checking for specifically yes/true and no/false, similar to the checkmarks option. Probably too much effort tho.
You can do this easily with a stored template that mimics what check_yes_no() does. Like this:

The stored template:
Code:
program:
	arguments(column, is_undefined, is_false, is_true);
	f = field(column);
	if is_undefined == 1 && !f then return 'yes' fi;
	if is_false == 1 && f == 'no' then return 'yes' fi;
	if is_true == 1 && f == 'yes'then return 'yes' fi
The template assumes that the column returns '' for undefined, 'yes' for true, and 'no' for false. Of course it can be adapted to other values. It works with any column type that returns those values, including bool columns.

Example use:
Code:
program:
	my_check_yes_no('#mybool', 0, 0, 1) & ' - ' & $#mybool & '.'
This shows the result of calling my_check_yes_no and the value in the column itself, separated by a '-'.

If you don't care about exact compatibility with the builtin check_yes_no() then you can pass the field value instead of the field name. Also you can use '1' and '' instead of '1' and '0', which would be a bit faster because it wouldn't need the '== 1' part of the test.
chaley is offline   Reply With Quote