4

I'm working on my first afform extension.

I've built a form, which works! I can submit values and create a contact.

However, I can't figure out how to pre-populate with default values. This is pretty important for the application. I've tried a number of things but none of them seem to work (not even the 'defn` one which came from a published example). Any suggestions? Note: I don't want to populate the form with the values from an existing contact. I need to insert new values into the form so when submitted, it creates a new contact.

 <af-form ctrl="modelListCtrl">
        <af-entity type="Contact" name="member" label="Member" />
        <div af-fieldset="member">
          <af-field name="first_name" ng-init="first_name = 'Betty'" />
          <af-field name="last_name" value="Smith" />
          <af-field name="do_not_email" defn="{type: 'checkbox', default: 1}" />
        </div>                                             
        <button ng-click="modelListCtrl.submit()">Submit</button>                                                                                              
  </af-form> 

1 Answer 1

2

Afform is still in beta so I expect this functionality to improve further, but currently it does support passing in an id via the url. It keys off the af-entity name property. So if you visit your form and add ?member=123 to the end of the url string it should load contact id 123 as the "Member". In that case it will update instead of creating a new contact.

1
  • 1
    Thanks for the follow up. I was hoping to set a value that does not come from the database - in other words, I want the form to submit a new contact, but I want the first and last names to be pre-populated on the form. Maybe not possible yet.
    – Jamie
    Commented Dec 22, 2020 at 1:20

Your Answer

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

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