Skip to content

Instantly share code, notes, and snippets.

@richardsweeney
Last active December 15, 2015 20:19
Show Gist options
  • Save richardsweeney/5317392 to your computer and use it in GitHub Desktop.
Save richardsweeney/5317392 to your computer and use it in GitHub Desktop.
Replace foreign letters used in field labels when dynamically creating field names. There's only a few here, these are the ones that are used in scandinavia.
$('#acf_fields tr.field_label input.label').live('blur', function()
{
var label = $(this);
var name = $(this).closest('tr').siblings('tr.field_name').find('input.name');
if(name.val() == '')
{
var val = label.val();
var ex = {
'ä': 'a',
'æ': 'a',
'å': 'a',
'ö': 'o',
'ø': 'o',
'é': 'e',
'ë': 'e'
};
for(letter in ex) {
var regex = new RegExp( letter, 'g' );
val = val.replace( regex, ex[letter] );
}
val = val.toLowerCase().split(' ').join('_').split('\'').join('');
name.val(val);
name.trigger('keyup');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment