Home > Community > Forums > Custom IC SKILL > Variable number of dialog box fields

Email

* Required Fields

Recipients email * (separate multiple addresses with commas)

Your name *

Your email *

Message *

Contact Us

* Required Fields
First Name *

Last Name *

Email *

Company / Institution *

Comments: *

 Variable number of dialog box fields 

Last post Mon, Feb 25 2013 3:17 PM by Andrew Beckett. 9 replies.
Started by thomas1000 21 Feb 2013 05:27 PM. Topic has 9 replies and 1222 views
Page 1 of 1 (10 items)
Sort Posts:
  • Thu, Feb 21 2013 5:27 PM

    Variable number of dialog box fields Reply

    I am trying to construct a dialog box with a variable number of fields, however,  the hiCreateStringField ?name parameter is supposed to be a single-quoted symbol reference so I cannot simply assign the result of hiCreateStringField to an array and then reference it.  I must have the wrong approach.  

    Does anyone know how to construct a form with a variable number of fields?  If so, can you point me in the right direction?  I want to be able to create fields in an indexed loop and read their values that way.

    • Post Points: 35
  • Thu, Feb 21 2013 7:47 PM

    • kb how
    • Top 100 Contributor
    • Joined on Fri, May 6 2011
    • Melaka, Melaka
    • Posts 76
    • Points 1,030
    Re: Variable number of dialog box fields Reply

    No sure it this that you're looking for.

    StringList = list("field1" "field2" field3" "field4")

    form = hiCreateAppForm(?name 'form ?fields foreach(mapcar str StringList hiCreateStringField(?name stringToSymbol(str) ?prompt str)))
    hiDisplayForm(form)

    This will process all string in StringList and create a stringField for the form.

    -How-
    • Post Points: 5
  • Thu, Feb 21 2013 7:54 PM

    • skillUser
    • Top 10 Contributor
    • Joined on Fri, Sep 19 2008
    • Austin, TX
    • Posts 2,567
    • Points 15,575
    Re: Variable number of dialog box fields Reply

    Hi Thomas,

    I think that you might want to auto-create the name for the ?name argument to hiCreateStringField using gensym() perhaps?  Or if you are within a numbered loop, you might just concatenate the number to a base name using something like concat('strField num) [where 'strField is the base name for each field and num is the loop variable].  You might consider looking at Solution Article 11106074 for some assistance.

    Hopefully this is the sort of thing that you are looking for?

    Regards,

    Lawrence.

    • Post Points: 20
  • Mon, Feb 25 2013 1:31 PM

    Re: Variable number of dialog box fields Reply

    Thanks for the inputs.  I can now create a form with default values filled in but there is still a missing component.  When I try to get the fields I have to reference them and everything I have tried either gives nil for all fields or the defaults and not the user entry.  Here is the code and when the dialog box dismisses it returns {nil nil nil}.  How do I get to the values that the user has filled into the form boxes?

    ;Get the values and print them in a list 

    procedure(FileFormCallback(theForm)
      let((
      ValueList
      )
      ValueList = nil
       for(i 0 2
       ValueList = append(ValueList list(nth(i theForm->fieldList)->value))
      );End for
      printf("%L\n" ValueList)
     );End let
     );End procedure
     

    ;Create the form fields


     procedure(DisplayForm()
     let((
      i
      )
     
      FieldList = nil
      N = 3
      for(i 1 3
       FieldList = append(FieldList list(hiCreateStringField(
         ?name gensym(sprintf(nil "CL%dLayerField" i))
         ?prompt sprintf(nil "Computational Layer %d Name:" i)
         ?defValue sprintf(nil "CL%dLayer" i)
         ?callback "FileFormCallback(hiGetCurrentForm())"
         ?editable t
         );End hiCreateStringField
        );End list
       );End append
      );End for

      FileForm = hiCreateAppForm(
       ?name 'FileForm
       ?formTitle "Test"
       ?callback "FileFormCallback(hiGetCurrentForm())"
       ?fields FieldList
       ?buttonLayout 'OKCancel
       ?unmapAfterCB t
      );End hiCreateAppForm
     );End let
     
     hiDisplayForm(FileForm)
    );End procedure

    • Post Points: 5
  • Mon, Feb 25 2013 1:48 PM

    Re: Variable number of dialog box fields Reply

    Continuing... Replacing the callback with the following returns the default values and not the user-entered values.  So I get back {"CL1LayerField" "CL2LayerField" "CL3LayerField"} even though different values have been entered into the form. 

    procedure(FileFormCallback(theForm)
      let((
      ValueList
      )
      ValueList = nil
     
       ValueList = append(ValueList list(nth(0 FieldList)->value))
       ValueList = append(ValueList list(nth(1 FieldList)->value))
       ValueList = append(ValueList list(nth(2 FieldList)->value))

      printf("%L\n" ValueList)
     );End let
     );End procedure

    • Post Points: 20
  • Mon, Feb 25 2013 2:46 PM

    Re: Variable number of dialog box fields Reply

    I think this is what you want:

    procedure(FileFormCallback(theForm)
      let((ValueList)
        ValueList=foreach(mapcar fieldName theForm->fieldList
          get(theForm fieldName)->value
        )
        printf("%L\n" ValueList)
      )
    )

    (note no need to use nth or anything like that, and will cope with any number of fields)

    Regards,

    Andrew.

    • Post Points: 20
  • Mon, Feb 25 2013 2:57 PM

    Re: Variable number of dialog box fields Reply

    Thanks, Andrew,

    That is nice and concise, better than the code I wrote, but when I try it and enter non-default values into the form and click "OK" I still get default values back in ValueList.  So we still haven't solved the original problem.  Somehow this code is returning the default values and not the filled-in values.

    • Post Points: 5
  • Mon, Feb 25 2013 3:02 PM

    Re: Variable number of dialog box fields Reply

    Here is the complete code - very simple because I am try ing to get this one thing working:

    procedure(FieldCheck(theForm)
     let((
      )
      hiSetCallbackStatus(theForm t)
     );End let
     );End procedure
     
    procedure(FileFormCallback(theForm)
      let((ValueList)
        ValueList=foreach(mapcar fieldName theForm->fieldList
          get(theForm fieldName)->value
        )
        printf("%L\n" ValueList)
      )
    )


     procedure(DisplayForm()
     let((
      i
      )
     
      FieldList = nil
      N = 3
      for(i 1 3
       FieldList = append(FieldList list(hiCreateStringField(
         ?name gensym(sprintf(nil "CL%dLayerField" i))
         ?prompt sprintf(nil "Computational Layer %d Name:" i)
         ?defValue sprintf(nil "CL%dLayer" i)
         ?callback "FieldCheck(hiGetCurrentForm())"
         ?editable t
         );End hiCreateStringField
        );End list
       );End append
      );End for

      FileForm = hiCreateAppForm(
       ?name 'FileForm
       ?formTitle "Test"
       ?callback "FileFormCallback(hiGetCurrentForm())"
       ?fields FieldList
       ?buttonLayout 'OKCancel
       ?unmapAfterCB t
      );End hiCreateAppForm
     );End let
     
     hiDisplayForm(FileForm)
    );End procedure

    • Post Points: 20
  • Mon, Feb 25 2013 3:16 PM

    Re: Variable number of dialog box fields Reply

    I found the problem.  I shut down Cadence and restarted and things all work fine now - I get the actual field values rather than defaults.

    Thanks for your help.

    • Post Points: 5
  • Mon, Feb 25 2013 3:17 PM

    Re: Variable number of dialog box fields Reply

    Well, for me if I enter fred, jim, harry in the three fields I get:

     ("fred" "jim" "harry")

    appearing in the CIW. So it works for me! (I cut and pasted the code above and used that, to be sure).

    No idea how it could be displaying the default values if the field values have been changed. You'd have to use ->defValue to get the default values...

    Regards,

    Andrew.

    • Post Points: 5
Page 1 of 1 (10 items)
Sort Posts:
Started by thomas1000 at 21 Feb 2013 05:27 PM. Topic has 9 replies.