Conditional read only on a field - rails-admin

It seems like it should be possible to pass in a conditional in place of the true/false that "read_only" is expecting for a field, however that doesn't seem to work. Is there a way to do a conditional read_only on a field based on that field's value?
Things I've tried that don't seem to work:
read_only true if self.blah runs but doesn't conditionally make it read_only
read_only true if bindings[:object].fieldname.blah gives error NoMethodError: undefined method []' for nil:NilClass at server start
read_only true if value.blah gives error NoMethodError: undefined method[]' for nil:NilClass at server start
read_only and passing in a lambda instead of just the true/false

Pass a block:
field :user, :belongs_to_association do
help "Required. Can't be changed after creation."
read_only do
bindings[:object].user_id.present?
end
end

Related

How to write an expression that evaluates a pipeline parameter to TRUE/FALSE?

I have a pipeline parameter fed by a config file in SQL.
Sometimes that parameter will be empty, not NULL but just empty ('').
How do I write an expression that will evaluate the parameter to TRUE/FALSE(blank/not blank) that I can put into my IF activity?
Basic question but thanks a lot.
I tried
#pipeline().parameters.x = ''
but it just told me Parameter x = '' was not found .......
You can use the below expression in the if activity to evaluate a parameter is empty or not.
#empty(pipeline().parameters.ok)
Sample demonstration:
A sample parameter ok.
For example, purpose I have created a string variable which I will use inside if to check the output.
In if give the above expression.
Inside True activities I have given a set variable activity and gave some value and did the same inside false activities.
Output when the parameter value is not given(empty).
Output when we gave any value to the parameter

Error: Incorrect parameter type for operator '<'. Expected Boolean, received Text

Here, I'm creating a new formulae field(text) based on the checkboxes. My requirement is if Attended, Canceled, Confirmed, Invited, Pending are unchecked show invited, if the confirmed checkbox is checked before the start date, The text to be populated as "confirmed". But, I'm getting error there. How can we compare those both. Any help
IF(AND(Attended__c ,Canceled__c ,Confirmed__c , Invited__c ,Pending__c),"False","Invited",
IF(OR(Confirmed__c,Confirmed__c<Start_Date_Time__c),"TRUE", "Confirmed",
IF((AND(Waiting_List__c,(!Confirmed__c)),"TRUE","Waitlisted","")))
The IF function is not set up correctly as written. The set up for the function is =IF(condition_is_met, value, value_if_not_met), so to have multiple IF's nested together, you must set it up like so: =IF(condition1_met, value, IF(condition2_met, value, value_if_condition2_not_met))
Right now you have it set up like =IF(condition1_met, value, value_if condition1_not_met, IF(condition2_met, value, value, value_if_condition2_not_met...

Azure Data Factory If Condition Not working as expected

I have the following within the dynamic expression of an ADF IF Condition:
#if(equals(variables('V_D_MAX_LOAD_ID_HIS'), ''), true, equals(variables('V_D_MAX_LOAD_ID'), variables('V_D_MAX_LOAD_ID_HIS')))
3 Cases can occur:
V_D_MAX_LOAD_ID_HIS is NULL and V_D_MAX_LOAD_ID is not null
-> in this case the value shpuld be true. The first (equals(variables('V_D_MAX_LOAD_ID_HIS'), '') will be true and so we will be in the true part of the if and the output should be true.
V_D_MAX_LOAD_ID_HIS and V_D_MAX_LOAD_ID have the same value
-> in this case the first equals will be false and we will jump into the false part where the second equals is. The second equals will be true, because both have the same value. So the Output should be true.
V_D_MAX_LOAD_ID_HIS and V_D_MAX_LOAD_ID have the same value
-> The first equals will be false again, so we jump into the second equals. This one will be false to, so the output should be false
But for some reason it doesn't work. In the 3rd case the output for some reason is still true and the activity for true of the 'If-Conidition-activity' gets executed.
Where is my mistake?
Just post an answer to end this question: This is because the variable wasn't properly set.
When I added the V_D_MAX_LOAD_ID_HIS i jsut copied the set variable
activity from the V_D_MAX_LOAD_ID which already existed. Then I never
changed the variable it should be assinged to. So both Activity set
the variable for V_D_MAX_LOAD_ID and V_D_MAX_LOAD_ID_HIS was never
properly set.

OR Formula in Word document not returning a value

I am working on a document where I need to be able to test multiple options in an if statement to see if one of them are true to decide if a paragraph displays on the document. I have been trying to figure out why my OR formula is not returning a value for me to test and I am not sure why it is not showing anything when it is updating.
I have inserted a field and added a formula within that field that I am hoping will work with my If statement to show the proper paragraph contens.
When I use an Or statement, even one as simple as { OR(1=1) } and update and toggle the field I get no result. From what I have read I should get a 1 or a 0, but I don't seem to get either of these results. The line just ends up blank. When I test it with my If formula it always shows the false result, even when the Or contains a true result.
The formula I am currently working with is:
{ IF{ OR("$event.eventType.name}" = "Birthday", "$event.eventType.name}" =
"Conference" } "Yes" "No" }
If I update and toggle the Or field it shows blank, no result either true or false, and makes the If formula show as false event on results where it should show true. As I mentioned above I even tried setting it to 1=1 and still could not get it to show as true. Not sure if there is something I am missing in working with the formula.
Any suggestions would be appreciated.
It's not clear from your post what $event.eventType.name is. Presumably it's a field generated by an Addin. In that case, you should be able to use something like:
{IF{={IF{$event.eventType.name}= "Birthday" 1 0}+{IF{$event.eventType.name}= "Conference" 1 0}# 0}> 0 "Yes" "No"}
or:
{={IF{$event.eventType.name}= "Birthday" 1 0}+{IF{$event.eventType.name}= "Conference" 1 0} \# "'Yes',,'No'"}
Note: The field brace pairs (i.e. '{ }') for the above example are all created in the document itself, via Ctrl-F9 (Cmd-F9 on a Mac); you can't simply type them or copy & paste them from this message. Nor is it practical to add them via any of the standard Word dialogues. The spaces represented in the field constructions are all required. If your fields are a kind of mergefield, you'll need to insert 'MERGEFIELD ' at the start of each one, thus:
{MERGEFIELD $event.eventType.name}

How to check the value of a boolean (set by user) with a variable string?

The user sets a boolean to true or false.
That does (exemple)
ElementNameone = true
ElementNametwo = false
ElementNamethree = true
Etc.
Now I have a string that is loaded from a file. The string called name can have values that are Nameone, Nametwo, Namethree, etc. Anyone of them at a time.
Now I would like to be able to do this
if Element .. name == true then
do something
Except I don't know how to do this properly.
I've tried to do
if not not ("Element" .. name) then
But it does not work.
Can anyone help ?
Thanks
Try this:
if _G["Element" .. name] == true then
-- do something
end
Note that this will work only if the variables set by the user (ElementNameone, .. etc.) are globals.
It's very likely you're solving the wrong problem.
You say "the user" sets these variables. How? An end user normally isn't going to be interacting directly with variables inside your program.
Can you use a table instead, with ElementNameone as the key and true or false as the associated value? If so, that would be a lot cleaner.

Resources