Automate

 View Only
  • 1.  Winshuttle Composer: implement toTitleCase

    Posted 04-09-2021 14:27
    Hello

    Does anyone know how to implement a toTitleCase function/rule in Composer so "The Content Of The Field Looks Like This"

    I know I can Validate the content if it doesn't match ^(?:[A-Z][^\s]*\s?)+$ but I'd like it to be translated automatically like it is doing with the toUpperCase function

    Thank you

    ------------------------------
    P-Y Robert | Senior Analyst – Collaboration Applications
    Domtar Inc.
    ------------------------------


  • 2.  RE: Winshuttle Composer: implement toTitleCase

    Employee
    Posted 04-12-2021 10:44
    Hi P-Y

    Would you consider CSS?  You can use something like this
    .textmc { text-transform:capitalize;}


    Match that up with the Class name setting on the field you want in mixed case

    as you type, it will always be mixed case.  I didn't use a shift key as I typed it.

    I tested this in Evolve, but it should also work in Foundation.  Another option is to use Javascript, but this is much easier.

    Best Regards,
    Sigrid

    ------------------------------
    Sigrid Kok
    PSE | Winshuttle NA
    ------------------------------



  • 3.  RE: Winshuttle Composer: implement toTitleCase

    Posted 04-12-2021 11:21
    Thanks a lot Sigrid, it works perfectly!

    I'm pretty good with Composer but CSS/Javascript aren't really my speciality, but now I know how easy it is for CSSs.  It can even replace many of my rules.

    Thanks! : )


    ------------------------------
    P-Y Robert | Senior Analyst – Collaboration Applications
    Domtar Inc. | 
    ------------------------------



  • 4.  RE: Winshuttle Composer: implement toTitleCase

    Employee
    Posted 04-12-2021 11:46
    Yay - glad it's working for you P-Y!

    I took the path of least resistance, which means CSS.  I'm no expert.  I found it in a Google search.  :)

    Best Regards,
    Sigrid

    ------------------------------
    Sigrid Kok
    PSE | Winshuttle NA
    ------------------------------



  • 5.  RE: Winshuttle Composer: implement toTitleCase

    Posted 04-14-2021 17:29
    I'm sorry I think it works but only visually.

    You will indeed see "Quick Brown Fox Jumps Over The Lazy Dog" on your form.

    But in the forms XML schema, the data will be the way you typed it in.
    So Composer will actually try to push "quick brown fox jumps over the lazy dog" to SAP if you typed it without holding the Shift key

    Would you know what I should search for the Javascript option?

    ------------------------------
    P-Y Robert | Senior Analyst – Collaboration Applications
    Domtar Inc. | 
    ------------------------------



  • 6.  RE: Winshuttle Composer: implement toTitleCase

    Employee
    Posted 04-14-2021 20:15
    So sorry P-Y. 

    I didn't fully test it.  Boo.

    To make it up to you, here's how to get it to work.  And I google searched this using something I found here:  https://www.freecodecamp.org/news/three-ways-to-title-case-a-sentence-in-javascript-676a9175eb27/
    but instead of passing in a value and returning a value, I'm passing in the field xpath and using $form.getValue and $form.setValue in the javascript to get and set the field value

    In the Javascript section on the Solutions tab, create a function like this:

    function titleCase(inputfield) {
        var fieldvalue = $form.getValue(inputfield);
        fieldvalue = fieldvalue.toLowerCase().split(' ')
        for (var i = 0; i < fieldvalue.length; i++) {
            fieldvalue[i] = fieldvalue[i].charAt(0).toUpperCase() + fieldvalue[i].slice(1);
        }
        $form.setValue(inputfield,fieldvalue.join(' '));
    }
    What it's doing - to the best of my knowledge:
    1. The xpath of the field you want to translate to mixed case is passed in, with single quotes around it as inputfield, ex: '/myfieldxpathgoeshere'
    2. We do a $form.getValue to get the current value of the form field and set it to fieldvalue
    3. Using Javascript functions, the string is broken up into an array of words, splitting up the sentence into individual words when it hits a space, as well as translating everything to lower case to start with
    4. It then loops via a FOR loop through each word, taking the first character and translating to upper case, and then appending the rest of the word, which is already in lower case
    5. Outside of the loop at the end, we use a $form.setValue call to set the form field to the join of all of the words, with a space in between

    Then setup a custom rule on the field you want in mixed case, and pass in the xpath of that field with single quotes around it:  
    titleCase('/myfieldxpathgoeshere');


    then this before
    looks like this after


    I checked and the form XML shows mixed case.

    Sorry again about getting your hopes up.  Mine were up, too.

    Hope this helps!
    Sigrid

    ------------------------------
    Sigrid Kok
    PSE | Winshuttle NA
    ------------------------------



  • 7.  RE: Winshuttle Composer: implement toTitleCase

    Posted 04-16-2021 00:18
    Yes that's it : )

    Thank you very much, and now I even know how to implement basic Javascript rules too if I need something similar again!

    ------------------------------
    P-Y Robert | Senior Analyst – Collaboration Applications
    Domtar Inc.
    ------------------------------