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)
  • Loading branch information
Log1x committed Aug 13, 2023
1 parent 01b9d86 commit 75cc01d
Showing 1 changed file with 12 additions and 2 deletions.
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 75cc01d

Please sign in to comment.