Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Thu May 25, 2017 3:40 pm

Hello

I have a form with two lists. Is it possible to populate one list based on the selected value in the other one?

Much appreciated

cmarin
 
Posts: 9
Joined: Fri Jun 05, 2015 12:46 pm

Fri May 26, 2017 6:38 am

Dear cmarin,

Thanks for your inquiry.
Did you mean there are two drop-down lists in PDF ? Could you please upload the input/expected file here or send them to us(support@e-iceblue.com) via email for investigation ?

Thanks,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Fri May 26, 2017 5:38 pm

Hi Betsy

yes I have 2 lists on the pdf.
i.e. one list has 2 items Fruits and Vegetables and the second one has a list of fruits and vegetables.
when the selected item changes in 1st list I'd like the 2nd list to update (when fruits selected in 1st list the 2nd list will show just fruits).

Hope this helps

Much appreciated

cmarin
 
Posts: 9
Joined: Fri Jun 05, 2015 12:46 pm

Tue May 30, 2017 3:21 am

Dear cmarin,

Sorry for late reply.
Please use JavaScript to meet your requirement, and accroding to your describtion, here is sample code for your kind reference.
Code: Select all
            //JavaScript code, and you could change it accroding to your specific requirement.
            String script
    = "var Fruits = [\"Apple\", \"tangerine\"];"
    + "var Vegetables = [\"lettuce\", \"Cabbage\"];"
    + "var v = event.value;"
    + "var List2 = this.getField(\"ListBox2\");"
    + "if (v == \"Fruits\")"
    + "{"
    + "List2.setItems(Fruits);"
    + "}"
    + "else if (v == \"Vegetables\")"
    + "{"
    + "List2.setItems(Vegetables);"
    + "}";
            PdfJavaScriptAction action1 = new PdfJavaScriptAction(script);
            PdfDocument pdf = new PdfDocument(@"F:\testing\ListSample.pdf");
            PdfFormWidget formWidget = pdf.Form as PdfFormWidget;
            //get the ListBox1
            PdfListBoxWidgetFieldWidget list = formWidget.FieldsWidget.List[0] as PdfListBoxWidgetFieldWidget;         
            //set the JS to the ListBox1
            list.Actions.KeyPressed = action1;
            pdf.SaveToFile("10678.Pdf");

Hope this helps. If there is any question, please provide us with input/expected file and the code you were using for investigation.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Tue May 30, 2017 4:05 pm

Thank you. I'll give it a try.

Can you please help me with calculi action.

I tried AFSimple_Calculate
Also I've tried var a = this.getField(""gst"").value; var b = this.getField(""qst"").value; this.getField(""total"").value = a+b;

If I put the action on a different field for LostFocus, it does the calculation.

please advise
much appreciated

cmarin
 
Posts: 9
Joined: Fri Jun 05, 2015 12:46 pm

Wed May 31, 2017 6:04 am

Dear cmarin,

Thanks for your response.
I have tested two cases you mentioned as below, and found the calculating function in result PDF doesn't work. And I have posted it to our Dev team, once there is any progress, we will let you know. Sorry for inconvneience caused.
Code: Select all
//case#1
AFSimple_Calculate("SUM", new Array("Text1", "Text2"));
//case#2
var one = this.getField("Text1");
var two = this.getField("Text2");
this.getField("total").value = one.value + two.value;


Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Fri Jun 30, 2017 8:40 am

Dear cmarin,

Thanks for waiting.
Now the issue has been fixed in Spire.PDF Pack(Hot Fix) Version:3.9.189, please download it and have a try.
Sample code for your kind reference.
Code: Select all
            //case#1 "Text1" and "Text2" are the name of TextBoxs
            String script = "AFSimple_Calculate(\"SUM\",new Array(\"Text1\", \"Text2\"));";
            PdfJavaScriptAction action = new PdfJavaScriptAction(script2);
            PdfDocument pdf = new PdfDocument(@"F:\testing\CalculatJsSample.pdf");
            PdfFormWidget formWidget = pdf.Form as PdfFormWidget;
             //get the total textbox field
            PdfTextBoxFieldWidget textbox = formWidget.FieldsWidget.List[4] as PdfTextBoxFieldWidget;
            textbox.Actions.Calculate = action;
            //if the textboxs already have values, Spire.PDF doesn't calculate that values firstly, so set the code below.
            PdfTextBoxFieldWidget textbox2 = formWidget.FieldsWidget.List[2] as PdfTextBoxFieldWidget;
            PdfTextBoxFieldWidget textbox3 = formWidget.FieldsWidget.List[3] as PdfTextBoxFieldWidget;
            textbox.Text = (int.Parse(textbox2.Text) + int.Parse(textbox3.Text)).ToString();
            pdf.SaveToFile("10687Calculate1.pdf");

Looking forward to your feedback.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Return to Spire.PDF