newism / craft3-fields

Address, telephone, email, embed and gender fields for CraftCMS 3.x
Other
54 stars 16 forks source link

Default Country Code doesn't do anything. #30

Closed webrgp closed 5 years ago

webrgp commented 6 years ago

I've set the default country on the address field, but when I create a new entry, the default country isn't selected.

Digging into the code, on fields/Address.php, from line 229, should be changed to:

$countryCode = $value ? $value->getCountryCode() : $this->defaultCountryCode;
$countryCodeField = Craft::$app->getView()->renderTemplate(
    'nsm-fields/_components/fieldtypes/Address/input/countryCode',
    [
        'name' => $this->handle,
        'value' => $countryCode,
        'field' => $this,
        'id' => $id,
        'namespacedId' => $namespacedId,
        'settings' => $fieldSettings,
        'countryOptions' => $this->getCountryOptions(),
    ]
);

and on templates/_components/fieldtypes/Address/input/countryCode.twig, change to:

{% import "_includes/forms" as forms %}
<div class="field-countryCode">
    <label for="{{ name ~ '-countryCode' }}">{{ 'Country' | t('app') }}</label>
    {{ forms.select({
        id: name ~ '-countryCode',
        name: name ~ '[countryCode]',
        value: value,
        options: countryOptions
    }) }}
</div>
webrgp commented 6 years ago

One quick note: after I've put the Google API key, I am still getting errors :-/

adrienne commented 6 years ago

I'm having the same problem.

leevigraham commented 5 years ago

@webrgp @adrienne I'm not sure what I was thinking with default country code. I think I might have copied that from the telephone input.

How would you expect a default country code to work? Would it render all the fields below? Are you planning to hide the auto complete?

leevigraham commented 5 years ago

Figured it out. https://github.com/newism/craft3-fields/releases/tag/0.0.14 should fix this issue.