Skip to content

Commit

Permalink
enhance(field): Add configurable placeholder default for the number f…
Browse files Browse the repository at this point in the history
…ield (Fixes #75) (#76)
  • Loading branch information
Log1x committed Aug 13, 2023
2 parents 01b9d86 + c381ab4 commit 6c2a736
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ If you are on Sage 10 and using my [ACF Composer](https://github.com/log1x/acf-c
```php
$field
->addField('my_number_field', 'phone_number')
->setConfig('placeholder', '+1 555-555-5555')
->setConfig('default_country', 'us');
```

Expand Down
14 changes: 12 additions & 2 deletions src/PhoneNumberField.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class PhoneNumberField extends \acf_field
*/
public $defaults = [
'country' => 'us',
'placeholder' => '+1 555-555-5555',
];

/**
Expand Down Expand Up @@ -80,9 +81,10 @@ public function render_field($field)
}

echo sprintf(
'<input type="tel" name="%s[number]" value="%s" />',
'<input type="tel" name="%s[number]" value="%s" placeholder="%s" />',
$field['name'],
$field['value']['number']
$field['value']['number'],
$field['placeholder'] ?? $this->defaults['placeholder']
);

echo sprintf(
Expand Down Expand Up @@ -111,6 +113,14 @@ public function render_field_settings($field)
'default_value' => $this->defaults['country'],
'choices' => (new PhoneNumber())->getCountries()
]);

acf_render_field_setting($field, [
'label' => __('Placeholder', 'acf-phone-number'),
'instructions' => __('The placeholder text for the phone number.', 'acf-phone-number'),
'type' => 'text',
'name' => 'placeholder',
'default_value' => $this->defaults['placeholder'],
]);
}

/**
Expand Down

0 comments on commit 6c2a736

Please sign in to comment.