0

Need some help with jQuery syntaxes, enter image description here I'm trying to do some kind of a search function in my form, it is working now with following code

<script>
jQuery(document).on('keypress', '[id*="fieldname2_"]', function(){
    jQuery(".cff-container-field").hide();      
    jQuery(".cff-container-field legend:contains('"+jQuery("[id*='fieldname2']").val()+"')").parent().parent().show()       
}); 

What i need to do is to make both ".cff-container-field legend" and "[id*='fieldname2']").val()

not case sensitive and normalize characters like č,ť,ä,ô...

i managed to normalize a string with

normalize('NFD').replace(/[\u0300-\u036f]/g, '')

but i don't know how to integrate it in existing jQuery above + to capitalize
Can anybody give some guidance or help with code? Total newbie in JS) here some more info about CFF plugin Customizing the form

Resolved with custom "contains" function

<script>
jQuery.expr[':'].icontains = function(a, i, m) {
    return jQuery(a).text().normalize("NFD").replace(/[\u0300-\u036f]/g, "").toUpperCase()
        .indexOf(m[3].normalize("NFD").replace(/[\u0300-\u036f]/g, "").toUpperCase()) >= 0;
};
    
jQuery(document).on('keyup', '[id*="fieldname2_"]', function(){
    jQuery(".cff-container-field").hide();  
    jQuery(".cff-container-field legend:icontains('"+jQuery("[id*='fieldname2']").val()+"')").parent().parent().show(); 
});
</script>
Exilion
  • 21
  • 2
  • `let content = $("[id*='fieldname2']").val().normalize("NFD").replace(/[\u0300-\u036f]/g, "").toUpperCase(); $(\`.cff-container-field legend:contains("${content}")\`).parent().parent().show()` – mplungjan Dec 12 '21 at 13:17
  • I have edited the post code, to show the full code of a script. I understood the logic, but after replace, search doesn't work – Exilion Dec 12 '21 at 13:41
  • Please post a [mcve] of your attempt, noting input and expected output, preferably in a [Stacksnippet](https://blog.stackoverflow.com/2014/09/introducing-runnable-javascript-css-and-html-code-snippets/) – mplungjan Dec 12 '21 at 13:43
  • Sorry I'm trying to add this function in a html field in Calculated Field Foms plugin on WP, the code posted is actually full code i added there and i don't really know how to make from it a reproducible example... I'll try to play with code you suggested, but as i can understand, it normalizes only input (content var), how could be also normalized field "legend"? – Exilion Dec 12 '21 at 13:59
  • Please update your question with relevant HTML and jQuery in a [mcve] where I can see what `[id*='fieldname2']` is and where the legend is found – mplungjan Dec 12 '21 at 14:01

0 Answers0