1

I can't figure out how to get this phone number input mask and Save/Edit input feature to play nice together.

jsfiddle

Basically I need the input field to be disabled unless Edit is selected, then it becomes enabled, then disabled again when Save is selected.

var phoneInputEdit = document.getElementById('phone-input-edit');
  if (phoneInputEdit) {
new Formatter(phoneInputEdit, {
    'pattern': '({{999}}) {{999}}-{{9999}}',
    'persistent': true
});

And

$(document).ready(function() {
$('.has-feedback input[name="Edit"]').click(function() {
    $(this).val(function(i,v) {
        return v === 'Edit' ? 'Save' : 'Edit';
    });
    //$(this).parent().prev().prev().next('img').toggle();
    $(this).parent().prev().prev().next('img').toggleClass('icon-inactive');
    $(this).parent().prev().prev('input[required]').prop('readonly',function(i,r) {
        return !r;
    });
  });
});

I tried wrapping the input mask in noConflict() but that didn't seem to work. If I get rid of all of the input mask code then of course the Save/Edit works which made me think it must be a library conflict. Maybe I did it wrong.

halfer
  • 18,701
  • 13
  • 79
  • 158
bunnycode
  • 275
  • 1
  • 13

1 Answers1

1

You're missing the disabled property. By adding/removing this property when you click the save/edit button it will work

Community
  • 1
  • 1
IlGala
  • 3,043
  • 3
  • 31
  • 46
  • 1
    Hi, thanks for responding. I added the disabled property, but clicking Edit/Save doesn't enable/disable it. Edit: Nevermind, I had added this to the html and not prop. This fixed it. Thanks! – bunnycode Nov 09 '15 at 19:13