CPCjosh Posted June 14, 2010 Share Posted June 14, 2010 Hi everyone! I'm a regular reader here. Just decided to register. I'm working on a project where I have a field that needs special treatment on just the first character of a line. I was thinking that I would need to utilize the charAt(index) method to define where the formatting goes, but I could use a little help. Many Thanks in advance! P.S. Though I'm a bit of a JavaScript n00b, most times I understand what I'm looking at, I'm just not very good at implementing it from scratch. Link to comment Share on other sites More sharing options...
hardwired Posted June 15, 2010 Share Posted June 15, 2010 Lets say your field name is "myLine". try creating this rule where your textbox would pull : firstchar = Left(Field("myLine"), 1); therest = Right(Field("myLine"), Field("myLine").length-1); return "<b>"+firstchar+"</b>" + therest ; Do whatever formatting you need that wraps the firstchar variable. Make sure you check the checkbox in the Rule Editor that reads Treat returned strings as tagged text. Link to comment Share on other sites More sharing options...
CPCjosh Posted June 17, 2010 Author Share Posted June 17, 2010 Thanks for that suggestion, I will give that a shot! Link to comment Share on other sites More sharing options...
CPCjosh Posted June 17, 2010 Author Share Posted June 17, 2010 By the way... Where can I find for reference the methods that you've used here and other examples... Like I said, I'm a JS noob and my library of knowledge on this stuff is slim. So to be able to bust out a solution like you did for me, would be fantastic! But I need to develop my knowledge of this stuff. Link to comment Share on other sites More sharing options...
Dan Korn Posted June 17, 2010 Share Posted June 17, 2010 I would do it like this: var fieldVal = Field("Name"); return "<b>" + TaggedTextFromRaw(fieldVal[0]) + "</b>" + TaggedTextFromRaw(fieldVal.substr(1));The calls to TaggedTextFromRaw will avoid potential problems with the data containing special characters that might otherwise be interpreted as tagged markup. By the way... Where can I find for reference the methods that you've used here and other examples... Like I said, I'm a JS noob and my library of knowledge on this stuff is slim. So to be able to bust out a solution like you did for me, would be fantastic! But I need to develop my knowledge of this stuff. See my signature for references about the JavaScript language. For FusionPro-specific functionality, there's nothing better than the Rules Guide. The Building Blocks dialog is a great resource as well. And you can search this forum and ask questions. Link to comment Share on other sites More sharing options...
CPCjosh Posted June 17, 2010 Author Share Posted June 17, 2010 Thanks Dan! I will use your method. Much Appreciated, as well as the reference. I didn't notice that before in your sig. Link to comment Share on other sites More sharing options...
CPCjosh Posted June 17, 2010 Author Share Posted June 17, 2010 So that worked perfectly! Thanks! I am now wondering how to modify this so that it will work with another situation. For an instance I see the 0 in brackets indicating the index for the character at which to change and then the first character of the substring later on showing which to start back up with, but what would I have to modify/change to make it look at word[0]? I've discovered the TagReferenceGuide...thats a lot of help Link to comment Share on other sites More sharing options...
Dan Korn Posted June 17, 2010 Share Posted June 17, 2010 I am now wondering how to modify this so that it will work with another situation. For an instance I see the 0 in brackets indicating the index for the character at which to change and then the first character of the substring later on showing which to start back up with, but what would I have to modify/change to make it look at word[0]? That's a little bit more complicated. You could write some code to search for the first space character and pull out the text before and after it separately. Or you could do something like this: var fieldVal = Field("Name"); var startMarkup = "<b>"; var endMarkup = "</b>"; return TaggedTextFromRaw(fieldVal).replace(/^(\S+)/, startMarkup + "$1" + endMarkup + "&[size=2]#[/size]32;"); This utilizes a very powerful feature of JavaScript called regular expressions: https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Regular_Expressions Link to comment Share on other sites More sharing options...
CPCjosh Posted June 18, 2010 Author Share Posted June 18, 2010 wow.. that's a bunch of greek. Thanks for taking the time to help! It worked perfectly. Now If I need to learn what's going on in the parenthesis... I'll look into it! Thanks again! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.