I have a rather long form where about 30 inputs are initially populated using ternary operators. I could use something like this: dmx-bind:value="serverconnect1.data.query.some_field?serverconnect1.data.query.some_field:serverconnect1.data.query.some_otherfield"
… but it would be preferable to use a more concise version: dmx-bind:value="some_field?some_field:some_otherfield"
Apart from being shorter, it’s also easier to read, debug, edit and create etc.
I could wrap the form in a repeat - then I could simply use the names as in version 2. Unfortunately, this doesn’t work with Single Record queries (or can it be made to work?). I might change the query, but the API file is used in quite a few other places… Also, it’s not ideal; I’m not repeating anything.
I thought of using a DataDetail component, but that doesn’t improve things much - eg column names would be prefixed like this: data_detail1.data.some_field
(I would have thought the context was unambiguous in this case. I wonder if the prefix is necessary.)
It’s not a very important issue but there’s some intrinsically unsatisfactory about cluttering up the code using the ‘default’ version. Perhaps I’ve overlooked an alternative or more sensible approach. I would be interested in any suggestions.
Well when your info comes from a server action it is referencing it like:
serverconnect.data.query.some_value
You can’t just use some_value - how would the script knows where it does come from, is it a variable, is it an input value or some other component on your page?
Not sure what exactly your request is here, but the code you posted is correct and this is the correct way to use it.
I didn't use 'some_value'. I used 'some_field' to indicate a database field/column - in the same way as you might use 'MyTable' etc. to indicate the type of thing you're referring to.
As I indicated, it's from a database query in server connect serverconnect1.data.query.some_field.
I'm well aware of how to use this code. I didn't mean to ask whether it was correct. I think you misunderstood my point.
There are many situations where you can use alternative, more concise forms to refer to things (in a general way). Eg in a SQL query, you can use column names, fully-qualified column names or aliases.
In Wappler, you may need to use serverconnect1.data.query.some_field to refer to a piece of data, or some_field may be all that's needed, if the context means there is no ambiguity as to what some_field refers to - for example in a repeat. Eg if the repeat is defined as: dmx-bind:repeat="sc_countries_list.data.qry_list"
.. then I can simply refer to the data within the repeat with the column name - eg 'country_name'.
In my example I have a form which will require almost 100 column references like this: serverconnect1.data.query.some_field. If I put the form in a repeat (although I'm only returning a single record), I don't need any of the serverconnect1.data.query. prefixes. The code is cleaner and more concise. Putting the form into a repeat is not a very satisfactory way of dealing with this; I'm only dealing with a single record. Also, as far as I can see, I would have to change the query type from 'single' to 'multiple' (although the query will only return a single record). Or is there a way, with a query defined as 'single'?
I was just asking for ideas/suggestions about dealing with such situations - which are very common. Generally, if I'm repeating the same expression over and over again, I might wonder if there's a better way to achieve the same result (eg putting that string/expression into a variable). I'm sure you know what I mean. I probably should have put this post into the coffee lounge section.
In general, I agree. However, I don't think it's a good argument for including lots of redundant code. I add prefixes to my column names so I can use search/replace reliably. Would you not feel there was something unsatisfactory about an identical expression being used repeatedly in a block of code, in a variety of contexts?
Based on your comment, perhaps you think it would be preferable to require that full names are used within repeats in Wappler, rather than simply the column name. A feature request?
For shortening expression paths, just but a detail region on the place where you want to use it - and then bind the main path to the detailed region, then the sub fields will be available in its scope.
However having too much shortened expression fields - might look nice but can be difficult to spot errors in. Because the field with the same name might be in the parent scope and it will be taken from there. So you might not always know where the value comes from and have difficult time debugging.
Using the Data Detail component? This was one of my initial suggestions and certainly a good option - but doesn't result in simply the column names, as in repeats.
I appreciate the point you mention in your second point. However, there are cases, like in repeats, where the column name alone is sufficient/unambiguous. Including the full expressions, as in my example, will make the code more difficult to read/debug, without any benefit. I might just use a repeat (but it would be good to know if a query defined as 'single' can be used - I expect not).