[Resolved] Detecting Empty Field

I was hoping someone could tell me why this code is not checking the structure_name field for being empty.

function btn_OK()
{
if (structure_name == '')
{
	var error_dialog_result = plugins.dialogs.showErrorDialog( 'Error',  'Fields Marked with * must have a value', 'OK')
	if (error_dialog_result =='OK')
	{
		return;
	}
			
	}
	else
	{
		databaseManager.setAutoSave(true);
		application.closeFormDialog();
	}
}

Thanks in advance

James

You are only checking for an empty string.

If the field never had a value, it won’t contain an empty string, but a null value.

So the proper code would be:

if (structure_name == '' || structure_name == null)

There is also a shortcut for doing this double check on strings:

if (!structure_name)

Paul

The field can contain an empty string or be NULL.
You can check for this like so:

if ( !structure_name ) {
  // field is empty
}

Hope this helps.