Inserting form with conditional logic to multiple tables

I’m generating a Bootrstrap 4 from a database insert. That’s a great feature btw! Is it possible to add this logic to it?

  1. Make a select option available only when the difference between of two date inputs are more than year.
  2. If that select options gets checked, dynamically add as many number input fields as there are years between the two date inputs.
  3. On submit, save some input fields to one table and other input fields to another.

Hi Per,
Yes all of this is possible:

You can use the dynamic attributes > disabled, to disable your select on certain condition. Read more:

Yes, you can use the select value as a repeat region expression:

In server connect, add two insert record steps, which insert in two different tables.

@Teodor. Thanks for your answer. I’m impressed by the versatility of Wappler. I was not expecting all this to be possible. However, I doubt that I could make this work by myself. Is there a way to hire someone from wappler for help?

There is a jobs category, you could create post a request in there to other Wappler users

1 Like

@Teodor @Hyperbytes Thanks, that’s good to know. I’m trying all sorts of things to figure out how to make a selct option availably only when the difference between of two date inputs are more than a year. Do you know how to calculate the difference between to date inputs?

There a lots of data manipulation options within the data picker like “Years Until” which should suit the purpose

.

2 Likes

But how do I even select two values (inp_StartDate.value and inp_EndDate.value) to start with? Should I use “Field”, “Expression” or “Template”? Can I write a javascript expression myself (I’m using moment.js) or can only use those in Wappler?

I tried this but it does not work.
inp_StartDate.value.monthsUntil(inp_EndDate.value > 12)

I had to set “12” to a number. Now it works, but in reverse. I want the select option to be abled (not disabled) when the condition is true. How can I fix that?

Can you be more specific please, perhaps the actual code line from the code view?

To method with that data picker is as below (i just used variables as an example)

Select the start date

Select the magic wand

image

Right click the value

image

Select Data Time then Months until

click the Date entry

image

And in the properties select the lightning bolt

image

Select the end date

Click select until expression builder closes.

This will generate the months until expression which you can then compare with any value you wish

If i follow what you want this should be allied to the “Show” Dynamic Attribute of the select

1 Like

I got the logic to work but I was hoping to have the select option visable, but disabled until my expression was true. Is that possible, or can I only show/hide the select option this way?

Assuming we are taking about a select form component then the Dynamic Attributes of the select allow the Disabled property to be set via the picker.

Using my demo based on variables rather than your data the resulting code would be something like this:

dmx-bind:disabled=“inp_StartDate.value.monthsUntil(inp_EndDate.value) <12”

I think that’s how I did it, exept I don’t know where you got the part “dmx-bind:disabled=” from? The expression still works in reverse though; the select option gets disabled when the difference is more than 12 months. I want it to be abled when the difference i more than 12 months.

The code is what is generated by wappler when you set the condition for “disabled” via the picker

image

If it works backward reverse the condition from “<” to “>”, logic of condition must be backwards

Just notice this, bracket is wrongly placed I believe

Should be

inp_StartDate.value.monthsUntil(inp_EndDate.value) > 12

Have set up a test page with form data and this works for me applied to the “Disabled” Dynamic Attribute

inp_StartDate.value.monthsUntil(inp_EndDate.value) < 12

Thank you very much! It works when inp_StartDate and inp_EndDate are set. Do you know how have the select option disabled from start (i.e. even when ther are not set)? I tried this but it did not work: inp_StartDate.value.monthsUntil(inp_EndDate.value) > 12 || (inp_StartDate.value == "undefined").

@Hyperbytes Forget about my last question, I just had to remove the quotes around undefined. Thank you very much for your help!

Try with:

inp_StartDate.value && inp_EndDate.value && inp_StartDate.value.monthsUntil(inp_EndDate.value) > 12
1 Like

That does not work unfortunately. Should I add it directly into the HTML or in the Dynamic Attributes field?