x-mask plugin: get unmasked value #2867
Replies: 4 comments 5 replies
-
Beta Was this translation helpful? Give feedback.
-
On the PHP side, using protected function prepareForValidation($attributes)
{
// Unmask values
$attributes['amount'] = (float) str_replace(',', '', $this->amount);
return $attributes;
} Then in a save function: public function save()
{
$data = $this->validate();
//... |
Beta Was this translation helpful? Give feedback.
-
I believe a current PR would expose it as an export from the mask plugin package where you could pass the input and the mask and it would give back the result with full mask removed. Of note, for masks, like money that would do |
Beta Was this translation helpful? Give feedback.
-
Currently dealing with this right now. I can't seem to find much information, but I came across this discussion. Was a native solution ever implemented for this? I'm trying to use x-model on a currency input, but I need the unmasked float value for calculations. |
Beta Was this translation helpful? Give feedback.
-
I am using the Mask plugin for formatting money value in a input field which is also a Livewire nested model.
This model have validation rule:
And it always raise validation error because the formated amount (say: 1,000,000) is not numeric but text.
Is there any way to bind the unmasked value (i.e: 1000000, instead of 1,000,000), or at least how to get the unmasked value using Alpine and/or Mask plugin?
Beta Was this translation helpful? Give feedback.
All reactions