You are viewing limited content. For full access, please sign in.

Question

Question

javascript help

asked on November 4, 2015

Hello,

I need some help as per the attached screenshot:

1. There is a table Wohnungsbeschreibung which has 3 columns, is it possible to have no. of rows as per selection in Anzahl Wohnungen?

2. I am trying to put the values of the table in an HTML field, however the problem is that the variable puts it in one line as all the values from Column1, then Column2 & then Column3, however the desired result should be 

Column1, Column2 & Column3, then it goes to row 2 & puts in the same format.

 

It would be also fine if the values are put in a hidden fields & then taken from there to the HTML field.

Please note that there is some text like Column1 is big Column2 is cool & Column3 is very cool, which has to be repeated overtime the row is added.

 

I am not very sure if the approach is right, but this is the best I could think of, please correct me if some other approach can be taken.

 

Thanks in advance!

Sahil

Screen Shot 2015-11-04 at 09.17.38.png
0 0

Answer

APPROVED ANSWER SELECTED ANSWER
replied on November 9, 2015

Hello Sahil,

 

The following is some script I think might help you get started in creating the correct formatting for your html activity with a table.

 

$(document).ready(function(){

 

  $('#q1').change(function(){ //#q1 is the drop down that selects how many rows

   

    var rownumber = $('#q1 select').val(); //same #q1 as above

    $('.form-del-field').trigger('click');

    for (i=0; i<rownumber; i++){

     

       $('#q4').trigger('click'); //#q4 is the cf-table-add-row button

    }

  });

 

  $('#q5, .form-del-field').on('change click',function(){ //q5 is your table

   

    var html = '';

    

    var col1 = '[id^=Field2\\(]'; //selectors for each column, '#q2' goes to '[id^=Field2\\(]'

    var col2 = '[id^=Field3\\(]';

    var col3 = '[id^=Field6\\(]';

   

    $(col1).each(function(){

      

      var index = $(col1).index(this);

      

      if ($(col1).eq(index).val() != '' &&

          $(col2).eq(index).val() != '' &&

          $(col3).eq(index).val() != '')

      {

     

        html += $(col1).eq(index).val()+' is big, '

               +$(col2).eq(index).val()+' is cool, and '

               +$(col3).eq(index).val()+' is very cool!\n';

      }

    });

   

    $('#q7 textarea').val(html); //#q7 is the multiline field

  });

});

 

The first part of this script will allow a drop down field to interact with the add and delete buttons on a table field, enabling you to trigger the creation and deletion of rows in a table dynamically with a drop down list.

 

The second part of the code indexes each row in your table which allows you to add text in-between and show the table values horizontally rather than vertically.  The in-between text in this case is “is big” “is cool” and “is very cool”  provided are also screenshots of the fields I used and how this code will affect the form.

 

I printed this text into a multi-line field so it can be passed to an email activity as a token, you can also modify the code to embed into an html and that will show in the custom html field; however, the html field cannot be passed to an email activity.

I hope this helps you get started and I wish you the best of luck.

 

1 0

Replies

replied on November 4, 2015

Hey Sahil

 

This sounds very complex, so my first recommendation is going to be to simplify some things.

 

  1. If you want users to determine the number of rows, then rely on the ADD button, rather than a drop down that causes a number of rows via Javascript.
  2. If I understand correctly, you want to take the values entered into the table and place them into a Custom HTML box for viewing? The information is already presented in the table for viewing, so I want to ask why you would want to duplicate that information into a Custom HTML box.
  3. You want newly created rows to replicate values of a previous row? The first row, the one row before? This is possible for Javascript, if this is what you want.

 

Update me with more information and we can discuss ways to solve this.

 

Thanks,

0 0
replied on November 4, 2015

Thanks Nathan,

1. I understand, but this is the functionality client is requesting, if it's not possible (at all) then of course I will recommend the add button.

2. I am actually at the time of submitting putting the variables with predefined text into another form which shows in HTML editor. That is why.

3. NO, there are different values in dropdown, so the user will decide what they want in the second row. Based on these values there is some text between columns which will be added & at the end the whole sentence will be provided in the HTML editor.

 

Thanks again,

Sahil

0 0
replied on November 4, 2015

Hey Sahil,

 

I highly recommend sticking to the Laserfiche designed ADD button. Its well tested and fully implemented already, so no need to do any hard work. If I were in your shoes, I would highly recommend to the client to take the existing option as it will save on your time, and it will be much less likely to cause errors/problems. This option is in everyones best interest.

 

As for the other points, I think it is going to be more difficult to convey exactly what you are trying to accomplish via text, so perhaps you would like to attend my CFW tomorrow and we can discuss it via call.

 

Thanks,

0 0
replied on November 4, 2015

Thanks Nathan,

I understand & fully agree, was thinking on same lines.

Of course, I think that is a good idea, however if in the meantime someone can give some input would be appreciated, as I am really running against time....

 

Regards,

Sahil

0 0
replied on November 4, 2015

While I agree with Nathan that if you can stick to the functionality Forms already has, it's best and easiest. However, if your users have a good reason to create a number of rows quickly, you can do that with javascript.

As far as the values from the tables being put in the HTML controls, if you want the HTML text to be stored in Laserfiche, using hidden fields and putting the variables for those hidden fields in the HTML is the way to go. As long as the data is in the hidden fields before you send the form to Laserfiche, the values of those hidden fields should stay on the form.

To add multiple rows at one time, you can use javascript to "click" on the Add button to create another row. If the users wants 3 rows, then you can do a loop and click the Add button 3 times. This allows you to use the "Add" functionality that Nathan was talking about and still satisfy your users.

0 0
replied on November 4, 2015

Thanks,

But I'm not storing it in lf, after the submission another form opens, which is basically HTML editor & has text, these variables are mapped to html & that's why I need the values in table to be retrieved. 

I can get the values, but they are not formatted as shown in table

& That is my main problem, adding routes I can live with.

0 0
replied on November 4, 2015

When you say "HTML editor" are you using some kind of jquery plugin or do you mean the HTML control that comes standard with Forms? And what is the content in that HTML editor/control? Is it an HTML table that looks like the table the user filled in?

If you're talking about the HTML control that comes with Forms and you're creating an HTML table that has the content of the table the user filled in, and nothing else. Then I'd take Nathan's advice above and make the table on the second form read-only. You can add CSS to make it display differently if needed.

If additional information needs to be displayed on the form before or after the table, you can always put an HTML control before and/or after the table with the rest of the content. And use CSS to format it so that it looks like it's all together.

If you really need to use the HTML control rather than the table filled in by the user, and you want to display the data in a table in that control, you can use HTML to create a table and with javascript, iterate through the table filled in by the user row by row, getting the values of the columns you need, and add those values row by row into the table in the HTML control, creating a new row as needed. A lot more work, but if that's what you need, I think it's do-able.

0 0
replied on November 5, 2015 Show version history

Thanks Sheila,

Sorry about the delay in answering, I'm actually using Jquery Plugin, same as this one for CKeditor.

The Editor has text & to fill in the gaps I want to use various fields on forms as variables.

 

& there exactly is the problem as I am not able to put the values as desired.

When I take the table as variable it puts the values in a row starting from Column1 (Row1, Row2,Row3), Column2 (Row1, Row2,Row3), Column3(Row1, Row2,Row3)

 

Where as I would like it to be in

Row1 - Column1, Column2

Row2 - Column1, Column2

Any Thoughts?

0 0
replied on November 5, 2015 Show version history

I downloaded, but haven't tried CKeditor.  I assume you could use javascript/jquery to populate the text in the editor with one of the methods available through their api. If so, then using jquery/javascript,  you can iterate through your table rows, getting the values for each column and use the right method in the editor's api to add it to the html editor.

Depending on your users' needs, you could also accomplish this with a multiline text field in forms. Of course, that doesn't give your users the ability to underline, highlight, add links, etc that CKeditor does.

Either way, you can't just use the table variable to drop the information in. You'll have to go row by row, column by column through that  table and format the information you retrieved in the manner you want to display it. I'm not an expert at js or jquery, but this is fairly easy to do and there are a ton of examples on the web. There may be some sample  code on this forum that will get you close to what you're trying to do.

0 0
replied on November 9, 2015

Wesley,

This is AWESOME!!!

Thanks a Million!!!

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.