Explore the community Forums Lectora Lectora Questions & Answers how to get the text of a textfield ?

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #330781 Score: 0
    Profile photo of Math Notermans
    Math Notermans
    Member
    contributor
    intermediate
    advanced
    friend finder
    junior moderator
    advocate
    LUC16 Attendee
    LUC16
    wise owl
    curious george
    118 pts
    @mnotermans5114

    Im working on a project where i need to get the text of a specific textfield onscreen in Lectora, and do stuff with it.

    First step for me is getting the proper clean text.

    And there an issue turns up. An issue with the formatting of text. Whenever a newline is entered in a Lectora textfield, it creates a span for it. So my single textfield in Lectora ends up in 5 spans with text. When getting the text with either JQuery .text(), innerText or Mike Wilcox amazing script getPlainText ( http://clubajax.org/plain-text-vs-innertext-vs-textcontent/ ) i get extra line breaks for each span, thus making my formatting in the Canvas looking off.

    So does anyone has a good solution to get the text of a Lectora textfield without having to deal with the spans ??

    Regards,

    ~Math

    #330783 Score: 2
    Profile photo of Math Notermans
    Math Notermans
    Member
    contributor
    intermediate
    advanced
    friend finder
    junior moderator
    advocate
    LUC16 Attendee
    LUC16
    wise owl
    curious george
    118 pts
    @mnotermans5114

    Often just describing an issue i run into, pops an idea in my brain how to fix the issue at hand. Again this time.

    So i had a textfield. Reading the text with Javascript in the described methods above resulted in extra linebreaks i wanted to avoid. Well reading it like this fixes that.

    var text2Use =””;
    var textSpans = document.getElementById(“text9482”).getElementsByTagName(“span”);
    for (var i = 0, l = textSpans.length; i < l; i++) {
    if(textSpans[i].textContent || textSpans[i].innerText != undefined){
    text2Use += textSpans[i].textContent || textSpans[i].innerText;
    }else{};

    Basically i loop through the Lectora generated spans in the Html and combine them into a new String to use…

    ~Math

    This post has received 2 votes up.
    #330836 Score: 2
    Profile photo of Lazaro Perez
    Lazaro Perez
    Member
    beginner
    intermediate
    curious george
    wise owl
    friend finder
    contributor
    profile
    Group Member
    picture perfect
    advanced
    28 pts
    @sirwise23

    Don’t you love it when you can answer you own question?

    Quick question. What kind of text box are you using to grab text from? Because if you use an Entry Field box from the Test & Survey menu, it creates a variable with the text so that you don’t have to take the straight text from the box. Like if I go in there now and create an entry box, it creates a variable named Entry_0001. If you grab the text from that variable I don’t think it will have the spans in it.

    Not sure what it is you are trying to grab and my JavaScript knowledge is pretty bad but I’ve found that there is almost always a work around of sorts.

    This post has received 2 votes up.
    #330853 Score: 0
    Profile photo of Math Notermans
    Math Notermans
    Member
    contributor
    intermediate
    advanced
    friend finder
    junior moderator
    advocate
    LUC16 Attendee
    LUC16
    wise owl
    curious george
    118 pts
    @mnotermans5114

    Hi Lazaro,

    True with input fields. But in this case its just a plain old textfield. With enters for paragraphs, and there you get the spanification 😉

    And as you state, indeed almost anything in Lectora can be done in at least 2 or 3 ways, but in this case plain text fields are a must.

    Regards,

    Math

     

     

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.