Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIO-8304: allow for multivalue masks to have blank input mask option #5672

Merged
merged 1 commit into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/components/_classes/multivalue/Multivalue.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,17 @@ export default class Multivalue extends Field {

/**
* @param {any} input - The input element on which the mask is to be applied.
* @param {string} mask - The mask pattern to apply to the input element. Exit early if no mask.
* @param {string} mask - The mask pattern to apply to the input element. Exit early and remove previous mask if no mask.
*/
updateMask(input, mask) {
if (!mask) {
if (input.mask) {
input.mask.destroy();
}
if (!this.component.placeholder) {
input.removeAttribute('placeholder');
}
input.value = '';
return;
}
this.setInputMask(input, mask, !this.component.placeholder);
Expand Down
15 changes: 15 additions & 0 deletions src/components/phonenumber/PhoneNumber.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Formio } from './../../Formio';

import {
comp1,
comp2
} from './fixtures';

describe('PhoneNumber Component', () => {
Expand Down Expand Up @@ -55,4 +56,18 @@ describe('PhoneNumber Component', () => {
})
.catch(done);
});

it('Should remove previous input mask when switching to a blank input mask', (done) => {
Formio.createForm(document.createElement('div'), comp2, {}).then((form) => {
const phoneNumberComponent = form.getComponent('phoneNumber');
const changeEvent = new Event('change');
phoneNumberComponent.refs.select[0].value = "Other";
phoneNumberComponent.refs.select[0].dispatchEvent(changeEvent);
setTimeout(()=>{
assert.equal(phoneNumberComponent.refs.input[0].querySelector('input').value, "");
assert.equal(phoneNumberComponent.refs.input[0].querySelector('input').getAttribute('placeholder'), null);
done();
},200);
});
});
});
23 changes: 23 additions & 0 deletions src/components/phonenumber/fixtures/comp2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export default {
components: [
{
"label": "Phone Number",
"applyMaskOn": "change",
"allowMultipleMasks": true,
"tableView": true,
"key": "phoneNumber",
"type": "phoneNumber",
"inputMasks": [
{
"label": "Canada",
"mask": "(999) 999-9999"
},
{
"label": "Other",
"mask": ""
}
],
"input": true
}
]
}
3 changes: 2 additions & 1 deletion src/components/phonenumber/fixtures/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
import comp1 from './comp1';
export { comp1 };
import comp2 from './comp2'
export { comp1, comp2 };
Loading