susan
susan

Reputation: 53

How to select a radio button by default in formly form angularjs

How do I set "onDemand" as default when the form is loaded? (Background: There is a hidden text box which should only be visible when "Predefine" is checked. Unfortunately, it is visible when the form gets loaded first. At this point I thought about making the onDemand checked by default to keep the textbox invisbile at first page load)

{"key":"discountType","type":"radioType", "templateOptions":{"options":   [{"name":"OnDemand","value":"OnDemand"},{"name":"Predefined","value":"Predefine"}]}},
                        {"key":"discValue","type":"input","templateOptions": {"type":"input"}, hideExpression: "model.discountType=='OnDemand'"}  
                    ]
 }

Upvotes: 0

Views: 1293

Answers (1)

susan
susan

Reputation: 53

Did some trial and error after sleeping over it and I got it. discount.discountInfo.discType="OnDemand"; resolved it.

var discount = this;
discount.title = title;
discount.discountInfo = {};
discount.fields=[{"key":"discountType","type":"radioType", "templateOptions":{"options":   [{"name":"OnDemand","value":"OnDemand"},{"name":"Predefined","value":"Predefine"}]}},
                    {"key":"discValue","type":"input","templateOptions": {"type":"input"}, hideExpression: "model.discountType=='OnDemand'"}  
                ]
discount.discountInfo.discType="OnDemand";

Upvotes: 1

Related Questions