NEW Conditional Set Filters

Options
Michael Udinski
Michael Udinski Administrator

ADMIN

edited October 2022 in ? Video Tutorials

We added 4 new conditional set filters:

 - first_notempty

 - first_notnulll

 - set_ifnotempty

 - set_ifnotnull


These will come especially in handy if you are updating records or objects but you only wish to update a field if the input is not empty or not null. Check out the tutorial to see how you can use them.



Comments

  • Daniel Rjeili
    Options
    Amazing ! can we add one more ? 😀  i suggested at request feature 
  • Tim Tyler
    Tim Tyler Member
    Options
     - Do you have any suggestions on how to intentionally overwrite a value with a blank (essentially delete out the value) since clearing the input will not work now?

    I am thinking we need the front end to pass a known delete value ([DELETE} or [NULL}, etc) but I was hoping, the bright minds over at Xano might have a cleaner way to handle this.
  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options
     - I just want to be sure that I'm following... you want to be able to not update something if the input is blank but also be able to clear it out at the same time with a blank value?
  • Tim Tyler
    Tim Tyler Member
    Options
     - We want to allow front end to pass only fields that have updates. Missing fields will keep current values. But how does the front end communicate when the user intends to clear the value from the field?

    Existing values:
    Name = Tim
    Active = False
    Message = This is a test

    UPDATE:
    Active = True

    UPDATE:
    Message = “”

    Using SetIfEmpty so the second update works, the last update would not work. The previous value would set into the Message field. Any ideas on how to clear Message?
  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options
    Hi  - definitely not the easiest on the eyes looking solution (esp if you have many fields) and certainly some nuance to think through in your front-end/UI but a solution is 100% possible, here's one way to think about:

    https://www.loom.com/share/a78f25efab37499fbef6e443595d0335
  • Tim Tyler
    Tim Tyler Member
    Options
     - Thank you for making the video. We needed up with something similar but without the extra inputs and without tge front end having to add something for the user just the awareness of the empty field. 

    Here’s what we did:

    If the field was not updated by the front end and so is missing then we use SetIfNotEmpty as stated before. However, if the front end passes a tag as the value on a field we catch that first and allow the value to be overwritten as empty in the EDIT. 

    By having the delete flag inside the value removes the need for extra inputs and UI controls. The front end just needs to apply the logic to add the when the user removes the value from the field. 

    I hope this helps others trying to build auto save forms on the front end as the user moves through each input value. 
  • Nathan Cox
    Options
    Thanks for the video. first_notempty is working great for text and integer properties.

    What conditional filter can I use for booleans?
  • Kevin Wasie
    Kevin Wasie Member
    Options
    Is there a way to do this so that you do not even need to include the column in the JSON?

    For instance

    User_Table
    • id
    • name
    • adress


    I want to send the following JSON
    {
    id:3,
    name: "Foo Bar"
    }I want only name to be updated, and address to remain the same.

    With first_ifNotNull, the above JSON clears the address field in the DB. 

    I cant use first_ifNotEmpty, because I want to be able to send {id: 1, address:""} and then set address to "". But, that then will not work with first_ifNotEmpty.

    thank you for assistance.
  • Josh Chambers
    Josh Chambers Member
    Options
    If anyone else is trying to use these on their authenticated user DB, note that you'll need to turn off "required" in the API input settings.
  • gbdoin
    gbdoin Member
    Options

    Would be nice to have real PUT/PATCH endpoints automatically generated. See the feature request #240

  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options

    @gbdoin just FYI Xano still performs full object replacements regardless of the verb

  • gbdoin
    gbdoin Member
    Options

    @Michael Udinski yes indeed, the feature request mentions using the "first_not[…]" filters above on an "edit record" request for all input fields automatically.

    This way, we could generate PATCH endpoints that actually patch the record without deleting the value if it is null (as an example for "first_notnull").