# Text, Password, and Numeric Input Templates

**URL:** <https://forum.inductiveautomation.com/t/text-password-and-numeric-input-templates/11374>\
**Category:** Ignition\
**Created:** [March 17, 2016, 2:55am UTC](https://forum.inductiveautomation.com/t/text-password-and-numeric-input-templates/11374 "2016-03-17T02:55:08Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmisztur2](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmisztur2/32/4243_2.png) [@cmisztur2](https://forum.inductiveautomation.com/u/cmisztur2)\
**Post date:** [March 17, 2016, 2:55am UTC](https://forum.inductiveautomation.com/t/text-password-and-numeric-input-templates/11374/1 "2016-03-17T02:55:08Z")

</div>

Attached is a set of text input templates that I am using in my project.

Caption = text displayed in upper right corner  
Required = input must have a non-zero length string or non-zero value  
Value = current value of input  
WantFocus = does this input want keyboard focus

And some code that I use to interact with these components:

```auto
from com.inductiveautomation.factorypmi.application.script import PyComponentWrapper #thanks Nick
from com.inductiveautomation.factorypmi.application.components.template import TemplateHolder

def focusInput():
	wHandle = shared.nav.getCurrentWindow()
	components = wHandle.rootContainer.getComponents()
	for component in components:
		if _giveFocus(component):
			return
		
		if isinstance(component,TemplateHolder):
			for templateHolder in component.getComponents():
				for templateComponent in templateHolder.getComponents():
					templateComponent = PyComponentWrapper(templateComponent)
					if(_giveFocus(templateComponent)):
						return
					
def _giveFocus(component):
	if hasattr(component,"WantFocus"):
		if(component.WantFocus):
			shared.developer.logDebug("Giving input focus to %s" % component.name)
			component.SetFocus()
			return True
	return False			

def _forceFocus(component):
	if hasattr(component,"WantFocus"):
		shared.developer.logDebug("Forcing input focus to %s" % component.name)
		component.SetFocus()
		return True
	return False	

def areInputsValid(setFocus = True):
	focused = not setFocus
	result = True
	
	wHandle = shared.nav.getCurrentWindow()
	if(wHandle != None):
		components = wHandle.rootContainer.getComponents()
		for component in components:
			if(not _isValid(component)):
				result = False
				if(not focused):
					focused = _forceFocus(component)
			
			if isinstance(component,TemplateHolder):
				for templateHolder in component.getComponents():
					for templateComponent in templateHolder.getComponents():
						templateComponent = PyComponentWrapper(templateComponent)
						if(not _isValid(templateComponent)):
							result = False
							if(not focused):
								focused = _forceFocus(templateComponent)
			
	return result
	
def _isValid(component):
	if hasattr(component,"IsValid"):
		if(not component.IsValid):
			shared.developer.logDebug("Invalid input found: %s" % component.name)
			component.Flash()
			return False
	return True
	
```
