创建高级网页表单
创建高级网页表单
标题和描述
CloudDeploy[FormFunction["city" -> "City", #city&, AppearanceRules -> <|"Title" -> "What's your city", "Description" -> "This form allows you to input your city"|>]]SubmitLabel 和 NextLabel
CloudDeploy[FormFunction["city" -> "City", #city&, AppearanceRules -> <|"SubmitLabel" -> "Go!"|>]]非文本值
AppearanceRules 中的大部分字段不需要字符串.
CloudDeploy[FormFunction["animal" -> "Animal", #animal&, AppearanceRules -> <|"SubmitLabel" -> [image], "Title" -> Import["ExampleData/turtle.jpg"], "Description" -> Style["What is this animal?", Blue] |>]]RequiredFieldIndicator
CloudDeploy[FormFunction[{"required" -> "Number", "optional" -> "Number" -> 0}, Identity, AppearanceRules -> <|"RequiredFieldIndicator" -> Function[Style[#, Red]] |>]]ItemLayout
"ItemLayout" 可用于决定在网格中元素显示的形式. 空白行和列被自动删除. 项目布局是响应式的,这意味着布局可适应浏览器窗口的宽度. 具体而言,项目布局在移动Web浏览器中可能看起来有所不同.
CloudDeploy[FormFunction[{"x" -> <|"Help" -> "type here"|>, "y" -> "Integer"}, Identity, AppearanceRules -> <|"ItemLayout" -> "Horizontal" |>]["x" -> "text"]]CloudDeploy[FormFunction[{"x" -> <|"Help" -> "type here"|>, "y" -> "Integer"}, Identity, AppearanceRules -> <|"ItemLayout" -> "Inline" |>]["x" -> "text"]]CloudDeploy[FormFunction[{"x" -> <|"Help" -> "type here"|>, "y" -> "Integer"}, Identity, AppearanceRules -> <|"ItemLayout" -> "Vertical" |>]["x" -> "text"]]CloudDeploy[FormFunction[{{"first" -> "Integer"}, {"second" -> "Integer"}}, Identity]]CloudDeploy[FormFunction[{{"label" -> "String"}, {{"second", #label } -> "Integer"}&}, Identity]]CloudDeploy[FormFunction[{{"number" -> "Integer"}, Table["x" <> ToString[i] -> "String", {i, #number}]&}, Identity]]当其中一个字段依赖另一个且都出现在同样页面时,定义一个表单会有用. 这可以通过使用带有诸如 TemplateSlot 符号的 Wolfram 语言模板语言实现.
CloudDeploy[FormFunction[{"state" -> "USState", "county" -> TemplateSlot["state"][EntityProperty["AdministrativeDivision", "Subdivisions"]]}, Identity]]可以通过 AutoSubmitting 封装强迫当字段被填入时,自动提交整个表单.
CloudDeploy[FormFunction[{"x" -> AutoSubmitting["Integer"], "y" -> "Integer"}, Identity]]有时在表单中有可变数目的字段会有用. 使用 RepeatingElement 重复一个字段.
CloudDeploy[FormFunction["field" -> RepeatingElement["String", {2, {1, 5}}]]]使用 RepeatingElement 的第二个参数,可以使子字段依赖其索引.
CloudDeploy[FormFunction["number of occupants" -> RepeatingElement[<|"Interpreter" -> "Integer", "Label" :> "room " <> ToString[i]|>, {{i, 2}, {1, 5}}]]]CloudDeploy[FormFunction["names" -> RepeatingElement[CompoundElement[<|"first" -> "String", "last" -> "String"|>]]]]CloudDeploy[FormFunction["field" -> RepeatingElement["String"], AppearanceRules -> <|"AddLabel" -> "Add", "DeleteLabel" -> "Delete"|>]]