1
$\begingroup$

I have an InputField search that provides search suggestions, but I want an animation necklace to be displayed while the search is 'busy'. I would also like this to be done using Dynamic rather than Manipulate.

A simplified version of the code has been provided below:

Dynamic[
 Column[{
   Row[{
     InputField[Dynamic[input], String, ContinuousAction -> True],
     Refresh[
      If[input != newInput, Animator[Appearance -> "Necklace"], 
       "Done"], TrackedSymbols :> {newInput}]
     }],
   Refresh[
   Column[Pause[2]; Characters[input], newInput = input;, 
     Frame -> All, ItemSize -> 20],
    TrackedSymbols :> {input}
    ]
   }, Spacings -> 0]
 ]

Here Pause[2] has replaced the 'busy' search calculations, and Characters[input] has replaced the search suggestions.

Currently:

  • Pause[2] is triggering twice instead of once.
  • Search suggestions and busy necklace appear simultaneously. (suggestions should appear after necklace disappears)
  • 'Busy necklace' does not animate.

End Goal:

  • 'Busy necklace' to appear immediately after input is changed.
  • Want to display an animated necklace while search is busy for the 2 seconds
  • Want the search suggestions and 'Done' message to display simultaneously

Here are some similar posts that may be helpful in solving my problem:

$\endgroup$
2
  • 1
    $\begingroup$ If you have the same Dynamic parent of those Refreshes then they will update each other anyway. $\endgroup$
    – Kuba
    May 26, 2015 at 8:16
  • 1
    $\begingroup$ Would be useful to post this as an answer $\endgroup$ May 27, 2015 at 8:27

1 Answer 1

1
$\begingroup$

Update:

Solved my problem with the help of Kuba's advice; making multiple Dynamics. Code listed below, for anyone who is interested.

Note: "SynchronousUpdating -> False" allows the animator to animate while search is 'busy'.

Row[{
  Column[{
    InputField[Dynamic[input], String, ContinuousAction -> True],
    Dynamic[
     Refresh[
      If[
       input != "",
       searchImage = Animator[Appearance -> "Necklace"]; Pause[1]; 
       searchImage = "";
       Column[Characters[input], Frame -> All, ItemSize -> 20],
       ""
       ], TrackedSymbols -> {input}
      ],
     Initialization -> {input = ""; searchImage = "";}, 
     SynchronousUpdating -> False
     ]
    },
   Spacings -> 0
   ],
  Dynamic[
   Refresh[
    searchImage,
    TrackedSymbols -> {searchImage}
    ]
   ]
  }]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.