Slug dependent field with accented characters

edited November 2017 in Share
Hi.
In one of my models i needed a slug (linked) field.
The problem was that i'm using spanish texts, and a title like "Sólo una prueba más" was "slugified" as "slo-una-prueba-ms".
All accented chars disappear.

Just by adding this line...
text = text.normalize('NFD');
...as the first line of the url_title function in linked_field_formatters.js (or fuel.min.js), did the job.

Maybe it's a good thing to add in the future for all the non-english titles. ;)

I hope this helps!

Comments

  • edited 10:45AM
    I didn't even know that function existed. What line did you add it?
  • edited 10:45AM
    First line of the function at fuel/modules/fuel/assets/js/fuel/linked_field_formatters.js

    // standard slugify borrowed from http://www.milesj.me/resources/snippet/13
    function url_title(text) {
    text = text.normalize('NFD');
    text = text.replace(/([^_-a-zA-Z0-9\s]|\,|\&)+/gi, '');
    text = text.replace(/\s+/gi, "-");
    text = text.toLowerCase();
    return text;
    }

    Maybe there's a better place for doing this?
  • edited March 2018
    Į wonder, why is it not working for me? I edited file fuel/modules/fuel/assets/js/fuel/linked_field_formatters.js as suggested by @weblar above, and it works neither for specific Lithuanian characters (ąžęūčėįų), nor for the phrase "Sólo una prueba más" - slugifying eats all the non-ascii characters... I also tried reloading the page, using a different browser (to avoid caching issues). no avail...

    EDIT: OK, I found the problem, it starts working when I edit likewise fuel/modules/fuel/assets/js/fuel/fuel.min.js file.
  • edited 10:45AM
    You can browse to fuel/build and it will compile your change in the linked_field_formatters.js file into fuel.min.js
Sign In or Register to comment.