RESOLVED - Clear/Reset Imput Field

Hello,

another question that I could not find an answer.

I’m trying to create a function that allows me to clean the fields of a form when sending or when I press a button to delete fields.

I created this function that actually deletes the fields from the values entered, but it tells me the input field as if there was a failure to compile, if normal it is yellow and gives it a red color as if there were an error of missing compilation.

What education should I give him to avoid this?

Thank you

function clearImput() {
$w(β€œ#ImptData”).value = null;
$w(β€œ#ImptEvent”).value= null;
$w(β€œ#ImputName”).value= null;
$w(β€œ#ImptCode”).value= null;
$w(β€œ#ImpuUser”).value= null;
$w(β€œ#ImputUrl”).value = null;
}

Hi,
Can you please share a screenshot ?
Roi

Hello,
thanks for your answer.

The first immaigne is at the loading of the page with the input fields not in error

the second and when the function is performed via the clear button


Thank you

Hi,
Thank you for the screenshots.
You need to set the input element to valid after you set the value to null/undefined/β€˜β€™.
Here is example:

$w('#input1').valid = true;

Good Luck!
Roi

I tried to put the statement that you have shown me, but I have always the same errorre

function clearImput() {
$w(β€œ#ImptData”).value = null;
$w(β€˜#ImptData’).valid = true;

$w(β€œ#ImptEvent”).value= null;
$w(β€˜#ImptEvent’).valid = true;

$w(β€œ#ImputName”).value= null;
$w(β€˜#ImputName’).valid = true;

$w(β€œ#ImptCode”).value= null;
$w(β€˜#ImptCode’).valid = true;

$w(β€œ#ImpuUser”).value= null;
$w(β€˜#ImpuUser’).valid = true;

$w(β€œ#ImputUrl”).value = null;
$w(β€˜#ImputUrl’).valid = true;
}

Ok,
Can you please share a link to your site and specify the name of the page ?
Roi

find solution with

$w(" #ImptData β€œ).value = null;
$w(”#ImptData").resetValidityIndication();

Thank You

1 Like

I wanted to reopen this discussion because I saw that it gives me errors sometimes when I clean the fields that are empty, so I tried to put an if to check that the fields are empty but it does not work. What’s the problem.

Thank you

function clearImput() {

if  (($w("#ImptData").value !== null) || ($w("#ImptData").value !== undefined ) ) { 
	$w("#ImptData").value = null; 
	$w("#ImptData").resetValidityIndication(); 
} 

if (($w("#ImptEvent").value !== null)  || ($w("#ImptEvent").value !== undefined) ) { 
	$w("#ImptEvent").value= null; 
	$w("#ImptEvent").resetValidityIndication(); 
} 

if (($w("#ImputName").value !== null) || ($w("#ImputName").value !== undefined) )  {		 
	$w("#ImputName").value= null; 
	$w("#ImputName").resetValidityIndication(); 
} 

if (($w("#ImptCode").value !== null) || ($w("#ImptCode").value !== undefined) ) {	 
	$w("#ImptCode").value= null;	 
	$w("#ImptCode").resetValidityIndication(); 
} 

if (($w("#ImpuUser").value !== null) || ($w("#ImpuUser").value !== undefined) ) { 
	$w("#ImpuUser").value= null;	 	 
	$w("#ImpuUser").resetValidityIndication(); 
} 

if (($w("#ImputUrl").value !== null) || ($w("#ImputUrl").value !== undefined) ) { 
	$w("#ImputUrl").value = null;	 
	$w("#ImputUrl").resetValidityIndication(); 
} 

}

Solution found, only the given date if it has never been compiled by null, the others do not give any value and that is why it gave error. I solved it but if someone has a better way I would be interested to know it.

function clearImput() {

if  ($w("#ImptData").value !== null) { 
	$w("#ImptData").value = null; 
	$w("#ImptData").resetValidityIndication(); 
} 

if ($w("#ImptEvent").value.length > 0) { 
	$w("#ImptEvent").value= null; 
	$w("#ImptEvent").resetValidityIndication(); 
} 

if ($w("#ImputName").value.length > 0) { 
	$w("#ImputName").value= null; 
	$w("#ImputName").resetValidityIndication(); 
} 

if ($w("#ImptCode").value.length > 0) { 
	$w("#ImptCode").value= null;	 
	$w("#ImptCode").resetValidityIndication(); 
} 

if ($w("#ImpuUser").value.length > 0) { 
	$w("#ImpuUser").value= null;	 	 
	$w("#ImpuUser").resetValidityIndication(); 
} 

if ($w("#ImputUrl").value.length > 0) { 
	$w("#ImputUrl").value = null;	 
	$w("#ImputUrl").resetValidityIndication(); 
} 

} 

Thank you

4 Likes

Great Job!
Roi

How to reset Upload Buttons? Im experiencing a problem with my form where I allow visitors to upload images of their properties they want to include my database. When they do, the previous image uploads of the previous use are still there.

$w ( β€œ#uploadButton2” ). reset

this does not seem to work

.reset()