• Resolved sanadaniyal

    (@sanadaniyal)


    I have a form with few fields like data entry. and on basis of selection from few fields (product and quantity) total price is calculated. There is a button ‘Add’ that I want to use to show the concatenated text of the detail of the product in some text field (fieldname10) and reset all other fields (except fieldname10).

    Query1:
    how to do: On button click I want to concat the text of a fieldname10 (Empty Text Field) with the detail of selected product with price, quantity and total price.

    Query2:
    On same button ‘Add’ I need fields of form to reset ( default values defined as placeholder)
    => Fields are of type Number, Dropdown.

    P.S: I am new to this technology and platform but this plugin seems like helpful. in my learning and research process so I dont have website link.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello @sanadaniyal

    Your questions are not specific about our plugin, these are basic HTML and javascript concepts.

    First, you cannot use the reset method of form, because you cannot restrict the reset to only some fields (the form would be reset as a whole). So, the alternative would be clear the values of the specific fields only.

    Assuming the fields to concatenate are: fieldname1, fieldname2, and fieldname3, and you want to assign the concatenated text to the fieldname10 field, and finally, clear the values of fields: fieldname1, fieldname2, and fieldname3

    I’ll to define a function to re-use the functionality with other fields if it would needed.

    – Insert a “HTML Content” field in the form with the following piece of code as its content:

    
    <script>
    function concatenate_and_reset(fields_list, result_field)
    {
        var result = '';
        for(var i  in fields_list)
        {
           result += ' '+jQuery('[id*="'+fields_list[i]+'_"]').val();
           jQuery('[id*="'+fields_list[i]+'_"]').val('');
        }
        jQuery('[id*="'+result_field+'_"]').val(result);
    }
    </script>
    

    Now, you simply should call the previous function as the onclick event of the button:

    
    concatenate_and_reset(['fieldname1', 'fieldname2', 'fieldname3'], 'fieldname10');
    

    as you can see the previous function accepts two parameters, a list with the names of the fields to concatenate and clear, and the name of the field where assign the concatenated text. So, from the onclick event of the button you can call this function with the list of fields you want.

    Best regards.

    Thread Starter sanadaniyal

    (@sanadaniyal)

    Thanks for the satisfactory response.

    There is one issue I am facing..
    I have a dropdown on form fieldname1. I have to use its value to be populated in other fields on selection so I have selected ‘Choice Value’ and thats working fine in that scenerio.
    Now issue is in the method concatenate_and_reset, one of my parameter to be concatenated is text of fieldname1 but its passing it by value if i simply pass fieldname1. How to pass text of the selection of feildname1 while not changing its property to ‘Choice Text’.

    Plugin Author codepeople

    (@codepeople)

    Hello @sanadaniyal

    The options “Choice text” and “Choice value” are referring to the information to submit, but in the equations there are used always the values of choices, never their texts.

    If you want take the text of the choice selected in a DropDown field, for example, the text of the choice selected in the fieldname1, the piece of code to use would be:

    
    jQuery('[id*="fieldname1_"] option:selected').text();
    

    If you want integrate it in the concatenate_and_reset routine, the process would be similar to:

    
    <script>
    function concatenate_and_reset(fields_list, result_field)
    {
        var result = '';
        for(var i  in fields_list)
        {
           if(jQuery('[id*="'+fields_list[i]+'_"]')[0].tagName == 'SELECT')
           {
               result += ' '+jQuery('[id*="'+fields_list[i]+'_"] option:selected').text();
           }
           else
           {
               result += ' '+jQuery('[id*="'+fields_list[i]+'_"]').val();
               jQuery('[id*="'+fields_list[i]+'_"]').val('');
           } 
        }
        jQuery('[id*="'+result_field+'_"]').val(result);
    }
    </script>
    

    I’m sorry, but the support service does not cover the implementation of the users’ projects (forms or formulas)

    Best regards.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Reset fields to default (placeholder values)’ is closed to new replies.