How to use value from current record in look up query field?

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1150
Joined: 2019-05-21 22:42
Location: Germany
Contact:

How to use value from current record in look up query field?

Post by onoehring » 2019-08-19 10:49

Hi,

I am not sure if this is even possible, so I turn to the magicians here in the forum.

The situation
I have boxes in multiple rows (Reihe, X), depth (Tiefe, Y) that are stacked on top of each other (Ebene, Z).
When I take a box, I can not pull it out of a stack, but I need to remove all boxes that are in front (Y) and all boxes that are on top of the box I want (Z).

The question
How can I use the coordinates (which are saved in the record) in a query for the ajax lookup of possible free locations?

Why
I want to create query for my lookup which does not show the current X-Y combination. This way it will be impossible to select the same row (X) and depth (Y) but simply a different height.

Example
Lets say, I want to pick the red box (coordinates: X=2, Y=1, Z=3). I would need to remove (in this order): (2,3,4) then (2,3,3) then (2,3,2)... at some point I can pick the red box. In my drop down which shows all empty available places, I would not be able to choose (2,1,*) because in this XY combination (21) it makes no sense at the time I am repositioning the box.
2ecomo_datenbank-projekt.de.png
2ecomo_datenbank-projekt.de.png (49.92 KiB) Viewed 2838 times
Olaf

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1150
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: How to use value from current record in look up query field?

Post by onoehring » 2019-08-20 07:13

Hi,

not the solution to the question I asked, but I found a workaround: I can use the before_update hook of that table to compare old (in database saved values) to the new values submitted. If they have the same XY combination I return FALSE in that function and the record will not be changed.

But still: Is it possible to manipulate the ajax lookup field with some value (from the current record)?

Olaf

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1806
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: How to use value from current record in look up query field?

Post by jsetzer » 2019-08-20 07:43

Hi Olaf,

if it becomes too complicated when using the built-in options, only, you are always free to add any custom input control to your form.

For example in hooks/TABLENAME.php function TABLENAME_dv():

Code: Select all

// new input without any formatting or label, yet
$html .= "<input name=\"whatever\" id=\"whatever\" class=\"form-control\" value=\"test\" />";
Then add a script using _header or _footer function or (what I prefer) add TABLENAME-dv.js and fine-tune your new input $j("#whatever"); for example move that new input to a different place.

Hide your original field using $j("#fieldname").closest(".form-group").hide();

If you need to, you can also use AJAX to retrieve values from a server side PHP script and populate the new input on client side.

On every change of your new input, copy the value into the hidden field for example by $j("#db_fieldname").val(myNewInputValue);
You can also do validations on every input change using JavaScript/JQuery and even use AJAX to do server side validation.

Having copied the new-input's value into the (hidden) existing field, you will see it in your $data variable on before/after insert/update.

This hack has helped me a lot when I wanted to add other controls like calendar, signature pad, many-to-many-dropdown, open-street-map map or others. To give an example, yesterday I have added a color picker using that method. The droddown button has been added using JQuery. There is a hidden "color" field which gets updated on every color change:

2019-08-20_09-38-08.gif
2019-08-20_09-38-08.gif (52.85 KiB) Viewed 2806 times

There is also my many-to-many dropdown combobox in that form. Again: same hack:

2019-08-20_09-40-34.gif
2019-08-20_09-40-34.gif (100.63 KiB) Viewed 2806 times

Hope this gives you a new idea!
Best,
Jan

PS: To get an similar layout and design, you need to wrap the new inputs into a <div class="form-group"> and add a <label> according to Bootstrap 3 specification https://getbootstrap.com/docs/3.3/css/#forms. Have a look at all the other generated inputs in template-files or in your browser's developer tools and take the HTML-structure as a template for your new form-group.
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1150
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: How to use value from current record in look up query field?

Post by onoehring » 2019-08-20 07:59

Hi Jan,

thanks for your suggestion. I am sure the time will come when I need to use a method like this. For now, I am probably fine with the workaround - as I am still not too much into jquery :-(

Olaf

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1806
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: How to use value from current record in look up query field?

Post by jsetzer » 2019-08-20 08:02

Sorry, I did not see that you have already answered your request by yourself.

Anyway, hope this idea will help anyone!

Best,
Jan
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1150
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: How to use value from current record in look up query field?

Post by onoehring » 2019-08-20 08:50

Hi Jan,
yes, I am thankful for your answer as it proposes a great way to intercept AG standard behavior.
Olaf

brudy
Veteran Member
Posts: 38
Joined: 2023-02-04 11:35

Re: How to use value from current record in look up query field?

Post by brudy » 2023-02-23 08:30

Hi Jsetzer,

Do you have a detailed procedure to add "color picker"?

Thanks

Rudy

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1806
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: How to use value from current record in look up query field?

Post by jsetzer » 2023-02-23 09:28

Don't remember which one I have used at that time (2018), there are so many out there:
https://www.jqueryscript.net/tags.php?/color%20picker/

Nowadays I'm using the (modern) browser's built-in (native) options:
Just change attribute type="text" to type="color" on <input/> control.

There are two options I'd like to show:
  1. Using standard jQuery
    chrome_l1TSs9DgLV.png
    chrome_l1TSs9DgLV.png (1.1 KiB) Viewed 1203 times
  2. Using AppGini Helper Javascript Library*
    chrome_azRLpM7yJQ.png
    chrome_azRLpM7yJQ.png (765 Bytes) Viewed 1203 times
    * commercial, I am the author
1. Using JQuery

You can do this with standard jQuery like this:

Code: Select all

jQuery("#FIELDNAME").attr("type", "color");
Output

chrome_v5Gxu5jjgM.png
chrome_v5Gxu5jjgM.png (53.53 KiB) Viewed 1203 times

Personally, I did not like the standard design:
1. The select-button takes the full row and
2. You cannot see the selected color very well due to the very thin line

That was the reason why I've coded a wrapper function in my AppGini Helper Javascript Library*, which is easy to use (one-liner) and automatically optimizes the button design according to my personal flavour ;-)


2. Using AppGiniHelper Javascript Library*

Code: Select all

// file: hooks/TABLENAME-dv.js
AppGiniHelper.DV.getField("FIELDNAME").toColorPicker();
Output

24HPEL7u3W.png
24HPEL7u3W.png (51.61 KiB) Viewed 1203 times

---
(Sorry, bad quality of compressed image due to size-limitation for attachments here)
ezgif.com-resize.gif
ezgif.com-resize.gif (215.39 KiB) Viewed 1203 times
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

brudy
Veteran Member
Posts: 38
Joined: 2023-02-04 11:35

Re: How to use value from current record in look up query field?

Post by brudy » 2023-02-23 15:38

In case I use your library, I just have to change the input text to color, copy your library.js in the hook directory and create a file TABLENAME-dv.js with the following code

Code: Select all

 AppGiniHelper.DV.getField("FIELDNAME").toColorPicker()
is it possible to see the html color code ( #xxxxxx ) ?

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1806
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: How to use value from current record in look up query field?

Post by jsetzer » 2023-02-23 16:13

In case I use your library, I just have to change the input text to color, copy your library.js in the hook directory and create a file TABLENAME-dv.js with the following code
That's almost correct. Paste file, include script in hooks/header-extras.php, then start coding in hooks/TABLENAME-dv.js
Instructions here:
http://www.appgini.de/docs/Javascript-L ... start.html

The field itself will show the color as a filled rectangle automatically.
is it possible to see the html color code ( #xxxxxx ) ?
After saving, the field will have a hex value in database, for example "#ff0000"

Have a look at the popup window which opens up on click: see the "R G B" at the bottom? On click, this toggles between RGB, HSL and Hex. Next to selecting a color from the color gradients you will also be able to enter color code values in each of these formats manually, for example paste hex-code.
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools


User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1806
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: How to use value from current record in look up query field?

Post by jsetzer » 2023-02-23 18:17

chrome_UYvdKNmqYn.png
chrome_UYvdKNmqYn.png (88.45 KiB) Viewed 1160 times
Looks good, @brudy, well done!
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

Post Reply