0

I'm trying to change some forms from quickforms to angularjs.
In quickforms you do this: $this->addEntityRef('Location_province', ts('Select Province'), ['entity' => 'state_province',]);

How do I replicate this in Angularjs? This is what I thought I should do but probably a class or something in CRM to already do this: In js file:

provinces = crmApi('state_province', 'get', {
      country_id: 1039,
    })
// do I process provinces to get to the values I want?
this.province = provinces
var ctrl = this

In the html template file I have:

<div crm-ui-field="{name: 'myForm.location_province', title: ts('Province'),}">
            <select
              crm-ui-select="{allowClear: true}"
              ng-model="$ctrl.myContact.location_province"
              multiple="single"
              class="big"
            >
              <option ng-repeat="option in $ctrl.province.values" value="{{option.name}}">
              {{option.name}}
            </option>
            </select>
            {{myform.location_province}}
          </div>

So its not working because the crmApi returns it in an array of multiple levels so is there a class to do this for me?

Thanks in advance!

1 Answer 1

2

Try below code

<div crm-ui-field="{name: 'myForm.location_province', title: ts('Province')}">
  <input
    name="myForm.location_province" crm-ui-id="myForm.location_province" 
     crm-entityref="{entity: 'state_province', api: {params: {country_id: 1039, is_active: 1, options:{sort:\'name\'}}}, select: {allowClear: true, minimumInputLength: 0, placeholder: ts(\'Select State\')}}"
    ng-model="myForm.location_province"
  />
</div>
1
  • Thanks! Exactly what I was looking for. Commented Jun 4, 2021 at 12:55

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.