Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Web CMS (TeamSite)
Extract 200 words from one textarea and display
System
hi all,
My DCT code is look like this
<?xml version="1.0" standalone="no"?>
<!DOCTYPE data-capture-requirements SYSTEM "datacapture6.0.dtd">
<data-capture-requirements type="content" name="Lufth">
<ruleset name="Lufth">
<item name="summary">
<label>Summary</label>
<description>Enter the summary of the message.</description>
<textarea cols="50" rows="5" wrap="physical" />
</item>
<item name="sub">
<replicant min="1" max="5">
<item name="sun_heading">
<label>Sub heading.</label>
<description>Text describing the Section.</description>
<text required="t" size="30"></text>
</item>
<item name="paragraph">
<label>Paragraph</label>
<description>Enter the Description of the message.</description>
<textarea wrap="virtual" rows="10" cols="50" />
</item>
</replicant>
</item>
</ruleset>
</data-capture-requirements>
Requirement is, If user enter the text in a item name Paragraph, then Form API shd extract 200 words from the textarea and display in itemname summary textarea in same DCT.
as i tried with regex like : $ParsedPara =~ s/((\s+\S+){199}).*$/$1/; but couldn't able to extract in javascript.
Can any one provide me sample code for the following requirement. All suggestions and sample / code will be highly appreciated.
Thanks.
Find more posts tagged with
Comments
Adam Stoller
What you showed as code wasn't FormAPI code - it was Perl code.
For FormAPI - I believe it would look something like this:
var ptext = IWDatacapture.getItem("/paragraph").getValue();
var stext = ptext.replace(/^(.{1,200})/, $1);
IWDatacapture.getItem("/summary").setValue(stext);
(completely un-tested - but I think it would be something like this)
--fish
Senior Consultant, Quotient Inc.
http://www.quotient-inc.com
jbonifaci
Fish, he wanted first 200 words...
Fish's code looks good, just change his regex to:
/^\s*((\S+\s+){,200}).*$/
Not tested, but should do what you're looking for. Unless I'm on crack atm, which could be, as I've been trying to get cubs tickets all day with no success... =(
Adam Stoller
Whoops - nice catch - I was doing first 200 characters ;-)
--fish
Senior Consultant, Quotient Inc.
http://www.quotient-inc.com
Migrateduser
Thanx a million Ghoti and all for the fav.
Now I have the code with me. can you do me a fav to make it ready.
<?xml version="1.0" standalone="no"?>
<!DOCTYPE data-capture-requirements SYSTEM "datacapture6.0.dtd">
<data-capture-requirements type="content" name="ceo_message">
<ruleset name="ceoMessage">
<item name="title">
<label>Title</label>
<description>Enter the title of the message.</description>
<text required="t" size="30" maxlength="125"></text>
</item>
<item name="summary">
<label>Summary</label>
<description>Enter the summary of the message.</description>
<textarea cols="50" rows="5" wrap="physical" />
</item>
<script>
<![CDATA[
var ptext = null;
var stext = null;
function init()
{
ptext = IWDatacapture.getItem("/paragraph").getValue();
stext = ptext.replace(/^\s*((\S+\s+){,200}).*$/, $1);
IWDatacapture.getItem("/summary").setValue(stext);
}
init();
]]>
</script>
<item name="image_main">
<label>Image</label>
<description>Select image file to be inserted in message.</description>
<browser extns=".gif,.jpeg,.jpg" initial-dir="/" ceiling-dir="/" size="50"/>
</item>
<item name="sub">
<replicant min="1" max="5">
<item name="sun_heading">
<label>Sub heading.</label>
<description>Text describing the Section.</description>
<text required="t" size="30"></text>
</item>
<item name="paragraph">
<label>Paragraph</label>
<description>Enter the Description of the message.</description>
<textarea wrap="virtual" rows="10" cols="50" />
</item>
</replicant>
</item>
<item name="image_faq">>
<label>Image</label>
<description>Select image file to be inserted in message.</description>
<browser extns=".gif,.jpeg,.jpg" initial-dir="/" ceiling-dir="/" size="50"/>
</item>
<item name="align">
<label>Aligngnment of Image</label>
<description>Choose the option to align</description>
<radio>
<option value="Left" label="Left" selected="t"/>
<option value="Center" label="Center"/>
<option value="Right" label="Right"/>
</radio>
</item>
<item name="date">
<description>Date of publish(mm/dd/yyyy)</description>
<text required="t" size="10"
validation-regex="^(?
?
?:0?[13578]|1[02])(\/|-)31)|(?
?:0?[1,3-9]|1[0-2])(\/|-)(?:29|30)))(\/|-)(?:[1-9]\d\d\d|\d[1-9]\d\d|\d\d[1-9]\d|\d\d\d[1-9])$|^(?
?:0?[1-9]|1[0-2])(\/|-)(?:0?[1-9]|1\d|2[0-8]))(\/|-)(?:[1-9]\d\d\d|\d[1-9]\d\d|\d\d[1-9]\d|\d\d\d[1-9])$|^(0?2(\/|-)29)(\/|-)(?
?:0[48]00|[13579][26]00|[2468][048]00)|(?:\d\d)?(?:0[48]|[2468][048]|[13579][26]))$">
<cgi-callout url="/iw-bin/Calendar.cgi" label="Calendar" window-features="width=460, height=300, resizable=yes,toolbar=no,scrollbars=yes"/>
</text>
</item>
</ruleset>
</data-capture-requirements>
Thanks
Michael
Hi Rishi
I am not quite sure what you are asking here -- are you asking for someone to finishing coding this for you? I hope not...
Anyhoo in case you are just looking for pointers in the right direction:
- you will need to address your paragraph field(s) correctly, not just "/paragraph", as it is in a replicant
- your paragraph is in a replicant therefore you need to decide if you are going to get the summary from just the first paragraph or iterate through the paragraphs until you get your 200 words (or run out of paragraphs)
- you need to decide when you want to populate the summary field with the automatic summary: every time a paragraph is updated? only when the form opens (as you have now), whenever a paragraph is updated and the summary field is empty?
Hope this helps.
Cheers
Michael
Migrateduser
Hi Michael.
Thanks for the fav.
well, i didn't meant to write the code for this requirement.
Thanks
RG
Migrateduser
Hi. Thanx you and Fish for the help. as you are the Masters on this tech.
is this is the right logic for that req.
The extract.js code is as follows.
var ptext = null;
var stext = null;
var oldParValue = null;
function init()
{
var ptext = IWDatacapture.getItem("/paragraph").getValue();
var stext = ptext.replace(/^\s*((\S+\s+){,200}).*$/, $1);
IWDatacapture.getItem("/summary").setValue(stext);
IWEventRegistry.addItemHandler("/paragraph", "onItemChange", handleExtract);
}
function handleExtract()
{
//Get the old value of the paragraph and update with new.
var newParValue = IWDatacapture.getItem("/paragraph").getValue();
if (oldParValue != newParValue)
{
var newSummaryValue = stext; //replace stext value
//this.form.stext.value=init(this.value);
//IWDCRInfo.setDCRName(dcrName);
//IWDatacapture.getItem("/paragraph").setValue("stext");
newParValue = IWDatacapture.getItem("paragraph").getValue();
oldParValue = newParValue;
//Now return true so that the save continues with this value
}
return true;
}
init();
As i am new on form API and going through the Form API 6.0 manual. will be thankfull for the help.
Thanks
RG
jbonifaci
My syntax was a little off last time and a made a couple adjustments. Replace this line:
var stext = ptext.replace(/^\s*((\S+\s+){,200}).*$/, $1);
With this:
var stext = ptext.replace(/^\s*(\S+(\s+\S+){0,199})(.|\n)*$/, "$1");