trigger calc only if element validated

Discussion in 'Community' started by ontarget, Jan 12, 2018.

  1. ontarget

    ontarget Member

    Level: Community
    Hi I am using a calc element to grab a group of elements and turn them into a bitly link.
    The calc is using ajax and is creating the bitly link before any elements have been populated.
    Is there any way of stopping a calc element from running until a few elements have been populated / validated?
    Thanks
     
  2. Sophist

    Sophist Moderator Staff Member

    Level: Community
    No. Not directly at least.

    But the calc element is running php, and the php can return an empty string if there is insufficient input to create a correct bitly link.

    I will leave it to others to comment on whether it is possible to stop the calc ajax from being fired by JS change events.
     
  3. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Professional
    That's kind of a all or nothing thing. If you enable AJAX calc, it'll fire whenever one of the referenced elements changes.

    But yeah, just code the calc so it doesn't call the bitly API if all the parts you need aren't empty.

    Altough tbh, I wouldn't use a calc for this, I'd use a form submission script, running onBeforeProcess, to make sure you only call bitly once.

    -- hugh
     
  4. ontarget

    ontarget Member

    Level: Community
    Cheers Sophist and Hugh - you set me on the right track.
     

Share This Page