Tap Forms app icon half
Tap Forms Forum text image
Blue gradient background

Exchange tips and ideas with the Tap Forms community

Search Results for 'script'

Viewing 15 results - 1,831 through 1,845 (of 2,989 total)
  • Author
    Search Results
  • #41244
    Sam Moffatt
    Participant

    I re-read this and thought I might be overthinking things, if you want a simple 1:1 mapping something like this might work for you. Create a script field and then use a switch statement to pick the right value.

    Here’s an example of autocompleting a country based on a “state” field. I use a switch because I think it’s pretty readable though you could construct an array as well:

    function Autocomplete_Country() {
    	var issuing_state = record.getFieldValue('fld-34f6d74d34354f63889f63a705b7d15f');
    	var country = '';
    	
    	switch (issuing_state)
    	{
    		case 'Washington':
    		case 'Oregon':
    		case 'Texas':
    		case 'Nevada':
    		case 'Arizona':
    		case 'Florida':
    		case 'New York':
    		case 'California':
    			country = 'United States of America';
    			break;
    		case 'New South Wales':
    		case 'Victoria':
    		case 'South Australia':
    		case 'Tasmania':
    		case 'Western Australia':
    		case 'Northern Territory':
    		case 'Australian Capital Territory':
    		case 'Queensland':
    			country = 'Australia';
    			break;
    		case 'British Columbia':
    		case 'Alberta':
    			country = 'Canada';
    			break;
    	}
    	
    	return country;
    }
    
    Autocomplete_Country();

    Basically in the case lines you put each of the values you want to match and then set a variable (in my case country) to be the value you want. You can then return it and it’ll display.

    Here’s the same thing implemented as a map/dictionary:

    function Autocomplete_Country_Map() {
    	var issuing_state = record.getFieldValue('fld-34f6d74d34354f63889f63a705b7d15f');
    
    	var state_map = {
    		'Washington':  'United States of America',
    		'Oregon': 'United States of America',
    		'Texas': 'United States of America',
    		'Nevada': 'United States of America',
    		'Arizona': 'United States of America',
    		'Florida': 'United States of America',
    		'New York': 'United States of America',
    		'California': 'United States of America',
    		'New South Wales': 'Australia',
    		'Victoria': 'Australia',
    		'South Australia': 'Australia',
    		'Tasmania': 'Australia',
    		'Western Australia': 'Australia',
    		'Northern Territory': 'Australia',
    		'Australian Capital Territory': 'Australia',
    		'Queensland': 'Australia',
    		'British Columbia': 'Canada',
    		'Alberta': 'Canada'
    	}
    		
    	return state_map[issuing_state];
    }
    
    Autocomplete_Country_Map();
    

    It’s a little more concise though you’re writing down the country name each time so possible to get it wrong.

    If you’re not after a direct 1:1 mapping of values between two fields, then we can continue down the earlier pathway. If you’re only after 1:1 this would work for you.

    One last piece is if you want to make the field editable but still autocompleted, this script will handle that for you. In this case there are three fields: state, country and the script field. State and country are text fields whilst the script field is what we use to retain some state and set values. The script below handles this and includes a reference to itself to allow manual overrides to be preserved when autocomplete would overwrite:

    function Autocomplete_Country() {
    	var issuing_state = record.getFieldValue('fld-34f6d74d34354f63889f63a705b7d15f');
    	
    
    	var issuing_country_id = 'fld-108b77c0b088457d90671dd71edf3247';
    	var issuing_country = record.getFieldValue(issuing_country_id);
    
    	var autocomplete_country_id = 'fld-cf8a4c138a3a437991182f17000580d6';
    	var previous_country = record.getFieldValue(autocomplete_country_id);
    	
    	if (issuing_country && issuing_country != previous_country)
    	{
    		return previous_country;
    	}
    
    	var country = '';
    	
    	switch (issuing_state)
    	{
    		case 'Washington':
    		case 'Oregon':
    		case 'California':
    			country = 'United States of America';
    			break;
    		case 'New South Wales':
    		case 'Victoria':
    		case 'Queensland':
    			country = 'Australia';
    			break;
    		case 'British Columbia':
    		case 'Alberta':
    			country = 'Canada';
    			break;
    	}
    	
    	record.setFieldValue(issuing_country_id, country);
    	form.saveAllChanges();
    	return country;
    }
    
    Autocomplete_Country();
    #41243
    Sam Moffatt
    Participant

    The complexity comes in that you need to encode the knowledge so that the computer can present it. Then once you’ve encoded that knowledge you need to access it to present it back to the user. Unfortunately Tap Forms doesn’t directly have an implementation that could hide that complexity from you so that means we’re implementing the complexity to make it look simple.

    Let’s tackle the data modelling problem first for encoding which brands and which countries. The scripts I presented have a few different options, which is the most comfortable for you:

    1. form based: create a new form with two fields: one with the brand name and one with a comma separated list of countries (you could create a country pick list using the multi-value popover or checkbox options to make data entry easier)
    2. pick list based: create one pick list with a list of all of the brands in it and then for each brand create another pick list that defines the countries
    3. fully script based: encode everything into a single script file (probably a bad idea if you have a lot of data)

    I think creating a new form to store it is probably the best path forward all told. Let me know which one of those approaches of storing the mapping data of “brand” to “country” makes sense for you and we can move forward with getting this sorted.

    #41235
    Daniel Leu
    Participant

    Yes, this can be done. Unfortunately, everytime you update your checkbox field, you have to click on Recalculate Formulas to get the update.

    Here is my field script:

    var hide_field_id = 'fld-xxx';
    var target_field_id = 'fld-xxx';
    
    var field = form.getFieldWithId(target_field_id);
    var status = '';
    
    if (record.getFieldValue(hide_field_id)){
    	field.hideField = true;
    	status = 'hiding field';
    } else {
    	field.hideField = false;
    	status = 'showing field';
    }
    
    document.saveAllChanges();
    
    status;

    Cheers, Daniel

    ---
    See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks

    #41234
    Jean-Pierre Hermans
    Participant

    Is it possible to hide different fields with a script? And if yes, can someone give an example because this is complete new for me.
    I have a checkbox and when it’s checked then some fields in that record needs to be hided.
    Thank you.

    #41233
    pierrot_rennes
    Participant

    Hi Sam,
    Thank you for your answer
    I went to see your code.
    I’m looking for something simple, so I’m going to refine my search.
    I have two selection lists: Brands and Countries.
    For example, when I select the Ravensburger brand in field 1, field 2 displays the country France
    Is it possible to define a script where each correspondence for brands and countries would be defined
    Thank you

    #41229
    Sam Moffatt
    Participant

    I’m not sure it’s possible to do that in Tap Forms with the default UI however I think you could easily create a form script with two prompters that did that for you. The input from the first prompter could be used to setup the second prompter which then sets the appropriate fields.

    A while back I did a post with a couple of different options on how you can make it work.

    #41220

    In reply to: Problem with If script

    Daniel Leu
    Participant

    Hi Victor,

    I noticed a few things:

    1. One of the pick list entries stated by a whitespace. You should remove that
    2. In your script, all branches need to be else if
    3. The address field selector should not be a checkmark, but a unique selector such as Single Value Popover

    With these changes, the script works for me.

    Here is the code I’m using:

    var address_field_id = 'fld-1f639ae503fe419b8473b02ea17d4ac4';
    var address_field = record.getFieldValue(address_field_id);
    
    let result = '';
    
    if (address_field=="newly identified - work address") {
    	result = record.getFieldValue('fld-943ab25fd0de42e7b8d1e5487c6a358b');
    } else if (address_field=="already identified - work address") {
    	result = record.getFieldValue('fld-11915a3f275a4938949714a664dc40bf');
    } else if (address_field=="newly identified - personal address") {
    	result = record.getFieldValue('fld-0e624f31b7af41b18fcb0262a7ec2a0d');
    }
    
    result;

    Please note that sometimes you need to press Recalculate formulas to get the record’s fields updated.

    Cheers, Daniel

    ---
    See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks

    #41218
    pierrot_rennes
    Participant

    Hi,
    I would like to be able to fill in a second field automatically based on the entry in another field.
    Is it possible in Tap Forms?
    Should we go through a script?
    For example, in field A, I enter a brand
    Field B automatically inquires with the corresponding country
    Thank you for your help

    #41210
    Victor Warner
    Participant

    Two issues:

    First issue: Finding the error in the script

    I am having an issue with the following script:

    var address_field_id = 'fld-1f639ae503fe419b8473b02ea17d4ac4';
    var address_field = record.getFieldValue('fld-1f639ae503fe419b8473b02ea17d4ac4');
    
    result = '';
    
    if (address_field=="newly identified - work address") {
    
    	result = record.getFieldValue('fld-943ab25fd0de42e7b8d1e5487c6a358b');
    	
    
    } else if (address_field=="already identified - work address") {
    
    	
    	result = record.getFieldValue('fld-11915a3f275a4938949714a664dc40bf');
     
     } else (address_field=="newly identified - personal address") {
    
    	
    	result = record.getFieldValue('fld-0e624f31b7af41b18fcb0262a7ec2a0d');
    
     }
    
    result;

    I am getting an error message in the script editor:

    Address chooser: SyntaxError: Unexpected token ‘{‘. Parse error., line:13

    Line 18 being the final else statement (“} else (address_field==”newly identified – personal address”) {“).

    I cannot see the error, although I am sure it is a typo on my part.

    Using a pick list as a basis to use data from other fields

    The aim of the above script is as follows:

    1. I field has a pick list
    2. The script field (using the code) will test which of the items in the pick list have been chosen and then get the value of another field in the database.

    The complete database is attached (although a simplified version of what I want to do).

    Is the script (as done or as corrected) the best way of this?

    Any help with this would be gratefully received.

    Attachments:
    You must be logged in to view attached files.
    #41175

    In reply to: Generate a photo sheet

    pierrot_rennes
    Participant

    Hi Brendan,

    Thank you for your answer

    I understood well for the labels mode and the layout.
    This is precisely why I asked the question ;-))
    Couldn’t it be an improvement of the software to integrate the possibility of creating photo boards in full page?
    several photo software allow you to make hot plates without using label format pages.

    All of our databases contain photos.
    It might be useful to be able to produce photo plates with a title field at least under each
    This would also allow you to have headers and footers, titles …

    Regarding color, I saw this possibility.
    But that’s not what I want ;-))
    It is related to the script concerning the coloring of a recording line.
    In my collections, I check the field if I have the object in collection and it works well thanks to your help and that of Sam
    So I would like that for the photo board mode, a field will be colored under the photo if this recording is checked in the collection.
    It may be complicated or impossible but I ask the question ;-))

    Thanks in any case for the responsiveness

    #41171
    Brendan
    Keymaster

    I think I missed the second part. But the script value did get updated after deleting a photo with my fix on the record details view though.

    #41151
    Brendan
    Keymaster

    Great video Sam! And as you may have seen in my comment on your Youtube video, I’ve fixed the bug with the script not running when you delete a photo.

    #41143
    Sam Moffatt
    Participant

    Another workaround for the list, create a new script field (I called mine “Empty Image Field”), open it up and it’ll drop in a bit of template code for you. If you double click on the image field in your field list on the left, it’ll insert the field ID for the image field. Then if you make the script look something like this, you’ll have a searchable field on if the image field is empty (image_01 is the name of my image field, it’ll like be var cover = ... for you):

    function Empty_Image_Field() {
    	var image_01 = record.getFieldValue('fld-e631165b67374734a3b8f384708b5922');
    	return image_01.length;
    
    }
    
    Empty_Image_Field();
    

    Set it to be a “number” field on the bottom left (default is text) and also tick “update records when saving” to run the script on all of your records. Then hit “Save”, it’ll take a moment for TF to update all of your existing records with the new value for the field (that’ll depend on how many records you have) and then you should be able to look for records that have zero images using the script field and looking for a value of 0.

    #41088
    Sam Moffatt
    Participant

    Thanks! I need to work on the audio quality, too many computer fans and background noise (need to close some more windows). I played with the screen recording tool I used a bit and found some noise cleanup options. Probably should script things better but I figured I’d put my money where my mouth was after suggesting doing video tutorials a while back.

    #41058
    Daniel Leu
    Participant

    TapForms comes with example forms for driver licenses and passports. The driver license form might be good starting point. Add a photo field, change class to license type, remove the sex and date-of-birth field. Maybe add a description field where you can note some license specific infos.

    Cheers, Daniel

    ---
    See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks

Viewing 15 results - 1,831 through 1,845 (of 2,989 total)