[CLOSED] MVC - how to exclude form field at runtime

  1. #1

    [CLOSED] MVC - how to exclude form field at runtime

    Hi guys,

    I have a Window with inside a FormPanel; the panel contains two textfield; I was wondering how can I exclude at runtime the second textfield using a parameter contained in the model.

    Seems simple but i Cannot find the correct sintax!

    More generally the question would be: how can I insert code snippet ( @if(Model.parameter == 0) ... ) inside the Window definition?

    Any suggestion is really appreciated!

    Thanks

            Html.X().Window()
                    .ID("FormId")
                    .Title("FormTitle")
                    .Width(windowWidth)
                    .Height(580)
                    .Layout(LayoutType.Fit)
                    .Closable(false)
                    .Border(false)
                    .Hidden(true)
                    .Resizable(false)
                    .Modal(true)
                    .Items(
                        Html.X().FormPanel()
                            .Url(Url.Action("Submit","Firm"))
                            .ID("FormPanelId")
                            .MarginSpec("0 0 0 0")
                            .Layout(LayoutType.VBox)
                            .BodyPadding(5)
                            .Defaults(Html.X().Parameter().Name("margins").Value("0 5 0 0").Mode(ParameterMode.Value))
                            .LayoutConfig(new VBoxLayoutConfig { Align = VBoxAlign.Left })
                            .Items(
                                Html.X().TextField()
                                    .FieldLabel("Name")
                                    .ID("Id1")
                                    .Width(componentWidth)
                                    .LabelWidth(labelWidth)
                                    .Margins("5 10 0 0")
                                    .ReadOnly(true),
    
                                Html.X().TextField()
                                    .FieldLabel("Surname")
                                    .ID("Id2")
                                    .Width(componentWidth)
                                    .LabelWidth(labelWidth)
                                    .Margins("5 10 0 0")
                                    .ReadOnly(true)))
    Last edited by Daniil; Nov 08, 2013 at 12:50 PM. Reason: [CLOSED]
  2. #2
    Hi @aguidali,

    Welcome to the Ext.NET forums!

    It is easier not to add a TextField rather than excluding.

    Example
    @{
        var X = Html.X(); 
    }
    
    <!DOCTYPE html>
    <html>
    <head>
        <title>Ext.Net.MVC v2 Example</title>  
    </head>
    <body>
        @X.ResourceManager()
    
        @(X.FormPanel()
            .Items(items => 
            {
                items.Add(new TextField() { FieldLabel = "TextField 1" });
    
                if (Model.AddSecondTextField)
                {
                    items.Add(new TextField() { FieldLabel = "TextField 2" });
                } 
            })
        )
    </body>
    </html>
  3. #3
    Ok,

    Thanks Daniil !!

Similar Threads

  1. [CLOSED] Razor Get field value from form
    By OriCoder in forum 2.x Legacy Premium Help
    Replies: 7
    Last Post: Feb 20, 2013, 12:33 PM
  2. Replies: 0
    Last Post: Aug 23, 2012, 11:55 PM
  3. [CLOSED] How to exclude a field from the Form?
    By vadym.f in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Jul 30, 2012, 7:40 PM
  4. Store - Exclude field names from data
    By glenh in forum 1.x Help
    Replies: 3
    Last Post: May 01, 2012, 7:05 AM
  5. [CLOSED] [1.0] Text field added runtime looses value
    By PoloTheMonk in forum 1.x Legacy Premium Help
    Replies: 11
    Last Post: Jan 27, 2010, 6:38 AM

Tags for this Thread

Posting Permissions