4
$\begingroup$

I am trying to use FormFunction[] to input data in my notebook. As it shows up when using FormFunction in a notebook (no web deploy) no default values are displayed (even if specified) only empty input fields although the defaults are returned correctly when accepting the Form.

enter image description here

Bug or feature ? Is there any option to enable the initial display of default values?

Meanwhile I came up with the following solution:


FormFunctionInit[l_, "Init" -> True] :=  
 FormFunction[FormObject[l][Cases[l, (a_ -> b_ -> c_) :> (a -> c)]]]  

FormFunctionInit[l_, ___] :=
 FormFunction[FormObject[l][]]

form = FormFunctionInit[
   {  
    "x1" -> "Number" -> 1,  
    "x2" -> "Number" -> 2,  
    "x3" -> "Number",  
    "x4" -> "Number" -> 4  
    }, "Init" -> True  
   ];

input = form[] // Normal

enter image description here

out[[3]]= {x1->1, x2->2, x3->55, x4->4}


Any suggestions for improvement avoiding my custom code?

$\endgroup$
0

1 Answer 1

1
$\begingroup$

I think you are most likely looking for the Input format. In the Details and Options section of FormFunction it specifies that you can have this form

FormFunction[formspec,func][<|"namek"->inputk,…|>]

inserts the inputs given into the form specified by FormFunction before evaluating the effect of the FormFunction.

  FormFunction[{
     "x1" -> <|"Interpreter" -> "Number", "Input" -> 1|>,
     "x2" -> <|"Interpreter" -> "Number", "Input" -> 2|>,
     "x3" -> "Number",
     "x4" -> <|"Interpreter" -> "Number", "Input" -> 4|>}][]

enter image description here

Notice: If you complete x3 field e.g. with number 3 then it returns the default (input) values for x1,x2,x3. In that case there is no need for a "Default". I am not sure though how these two are contrasted.

  Out= <|"x1" -> 1, "x2" -> 2, "x3" -> 3, "x4" -> 4|>
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.