Property binding error on self.props.text

Hi,
Can anyone confirm if it is a bug or expected output?

  1. When I bind a self.props.text of a textfield using an expression and script transform, i’m not getting my output as self.props.text = “Exists” whereas if I use return statement it works.
  2. When i did a mistake as self.props.tex = “Exists”, it created a new props property as tex and return “Exists” to it.

Setting self.props.something in a transform is a ‘side effect’, and not generally using transform the way they’re “meant” to be used. The recommended way to use any transform, including scripting, is to mutate the incoming value and transform it into something else. In a script transform, the correct way to do that is via the return statement; the entire script transform is modeled as a function, that accepts the value of the previous step of the binding, then returns the modified value.

Writing to other properties is possible, as you noticed; setting self.props.tex to some value is going to create a new property, because you’re telling the component "here’s a new value for props.tex". However, it shouldn’t be necessary in 90% of cases, and should be avoided. Think about the maintenance problem; in six months, or a year or two, if you come back to this screen, are you going to expect the enabled property to be toggled by a script “hidden” in the self.props.text binding? Instead, you should write your transform as follows, then add a second binding on a self.props.enabled that checks whether self.props.text is EXISTS.

if value:
	ds = system.db.runNamedQuery("SELECT2CUSTOMERS")
	for row in range(ds.rowCount):
		if ds.getValueAt(row, "DETAIL_CODE") == value:
			return "EXISTS"
	else:
		return "UNIQUE CODE"
else:
	return ""

Thanks! Appreciate your prompt response.

Noted on the explanation.
Agreed that enabled should on its binding, I was scripting here on enable property just to check if my code works (since self.props.text didn’t give expected result).
As a beginner and self learner, I wasn’t aware that ‘else’ can be used with for loop :slight_smile:
Thanks!

1 Like