omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Pre-populate custom UI datepicker with selected date/time

    Editorial
    2
    8
    4116
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • ryanlaner
      ryanlaner last edited by

      Does anyone no how to pre-poplutate the datepicker UI with a provided date/time when the UI pops up. It defaults to today, but I want to provide a selected date to edit from. I can see how to do this from a python script but was looking for an easy way to set the date using the Custom UI workflow action. Workflow would be following:

      1. Select date/time in file
      2. If date/time selected, parse into appropriate format, else default to today
      3. Custom UI datepicker would pop up with selected date ready for editing
      4. Output new date for updating file

      /ryan

      1 Reply Last reply Reply Quote 0
      • omz
        omz last edited by

        It's currently not possible to do this without any Python. You can use Python in a Custom UI action though, e.g. something like:

        import workflow
        view = workflow.get_view()
        datepicker = view['datepicker1']
        datepicker.date = ...
        
        1 Reply Last reply Reply Quote 0
        • ryanlaner
          ryanlaner last edited by

          That's what I was looking for, thanks! I didn't want to do the whole ui in Python, just inject some data like you suggested. I wasn't aware I could do this actions in the custom UI.

          1 Reply Last reply Reply Quote 0
          • ryanlaner
            ryanlaner last edited by ryanlaner

            I guess I spoke too soon. I tried adding the following action in the datepicker as a run Python script but it does nothing.

            import workflow
            from datetime import datetime
            
            input = workflow.get_variable('date')
            dt = datetime.strptime(input, '%Y-%m-%d')
            
            view = workflow.get_view()
            
            datepicker = view['datepicker1']
            datepicker.date = dt
            

            I have run the first part of the code in a python script at the workflow level to verify the datetime object is being created correctly and it appears to be.

            Am I missing something?

            1 Reply Last reply Reply Quote 0
            • omz
              omz last edited by

              Wehre exactly did you add the script? Is it run at all?

              1 Reply Last reply Reply Quote 0
              • ryanlaner
                ryanlaner last edited by ryanlaner

                I added it as an action within the custom UI (attached to the datepicker object). Thought that was what you meant.?

                It doesn't seem to run at all.

                This Change Date workflow does what I want for populating the selected date but I couldn't figure out how it was doing it anywhere in the workflow. My workflow is different but this piece is what I need.

                1 Reply Last reply Reply Quote 0
                • omz
                  omz last edited by

                  @ryanlaner I think you should add this to the action of the main view. When you select nothing in the UI editor, the embedded workflow editor is for "view appeared". An action added to a date picker would run when the date picker changes (by user action), and setting a different date from there probably doesn't work and isn't what you want anyway.

                  1 Reply Last reply Reply Quote 0
                  • ryanlaner
                    ryanlaner last edited by

                    That was it. Thanks!

                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post
                    Powered by NodeBB Forums | Contributors