> For the complete documentation index, see [llms.txt](https://docs.devolutions.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.devolutions.net/powershell-universal/es/comandos-de-powershell/new-udform.md).

# New-UDForm

New-UDForm crea un formulario de PowerShell Universal que contiene controles de entrada que informan de sus valores cuando se hace clic en el botón de envío.

### Sinopsis

Los formularios pueden contener cualquier conjunto de controles de entrada. Cada uno de los controles informará de su valor al formulario cuando se haga clic en el botón de envío.

### Sintaxis

```powershell
New-UDForm [-Id <String>] [-OnValidate <Endpoint>] [-SubmitText <String>] [-CancelText <String>] [-ButtonVariant <String>] [-ClassName <String>] [-DisableSubmitOnEnter] [-Script <String>] [-OutputType <String>] [-ShowBackButton] [<CommonParameters>]

New-UDForm [-Id <String>] -Children <ScriptBlock> -OnSubmit <Endpoint> [-OnValidate <Endpoint>] [-OnProcessing <ScriptBlock>] [-OnCancel <Endpoint>] [-SubmitText <String>] [-CancelText <String>] [-ButtonVariant <String>] [-ClassName <String>] [-DisableSubmitOnEnter] [<CommonParameters>]

New-UDForm [-Id <String>] -OnSubmit <Endpoint> [-ButtonVariant <String>] [-ClassName <String>] -Schema <Hashtable> [-UiSchema <Hashtable>] [-FormData <Hashtable>] [-DisableSubmitOnEnter] [<CommonParameters>]
```

### Descripción

Crea un nuevo formulario. Los formularios pueden contener cualquier conjunto de controles de entrada. Cada uno de los controles informará de su valor al formulario cuando se haga clic en el botón de envío.

### Parámetros

#### -Id

El ID del componente. Su valor predeterminado es un GUID aleatorio.

```
Required?                    false
Position?                    named
Default value                [Guid]::NewGuid().ToString()
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -Children

Controles que componen este formulario. Puede ser cualquier combinación de controles. Los controles de entrada informarán de su estado al formulario.

```
Required?                    true
Position?                    named
Default value
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -OnSubmit

Un bloque de script que se ejecuta cuando se envía el formulario. Puede devolver controles desde este bloque de script y el formulario se sustituirá por el bloque de script. La variable $EventData contendrá una tabla hash con todos los campos de entrada y sus valores.

```
Required?                    true
Position?                    named
Default value
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -OnValidate

Un bloque de script que valida el formulario. Devuelve el resultado de una llamada a New-UDFormValidationResult.

```
Required?                    false
Position?                    named
Default value
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -OnProcessing

Un bloque de script que se llama cuando el formulario comienza el procesamiento. El valor devuelto por este bloque de script debe ser un componente que muestre un cuadro de diálogo de carga. El bloque de script recibirá los datos actuales del formulario.

```
Required?                    false
Position?                    named
Default value
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -OnCancel

Un bloque de script que se llama cuando se cancela un formulario. Útil para cerrar formularios en modales.

```
Required?                    false
Position?                    named
Default value
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -SubmitText

Texto que se muestra dentro del botón de envío. El valor predeterminado es 'Submit'.

```
Required?                    false
Position?                    named
Default value                Submit
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -CancelText

Texto que se muestra dentro del botón de cancelación. El valor predeterminado es 'Cancel'.

```
Required?                    false
Position?                    named
Default value                Cancel
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -ButtonVariant

Tipo de botón que se muestra. El valor predeterminado es text. Los valores válidos son contained, outlined, text.

```
Required?                    false
Position?                    named
Default value                text
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -ClassName

Una clase CSS que se aplica al formulario.

```
Required?                    false
Position?                    named
Default value
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -Schema

Define un formulario basado en una tabla hash de esquema. Esta versión de los formularios se basa en react-jsonschema-form.

```
Required?                    true
Position?                    named
Default value
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -UiSchema

Se utiliza para modificar el orden de los campos (consulte la documentación)

```
Required?                    false
Position?                    named
Default value                @{}
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -FormData

```
Required?                    false
Position?                    named
Default value                @{}
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -DisableSubmitOnEnter

Desactiva la funcionalidad por la que pulsar Intro en un cuadro de texto envía el formulario del que forma parte.

```
Required?                    false
Position?                    named
Default value                False
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -Script

Se utiliza para generar formularios automáticamente a partir de scripts en su entorno de PowerShell Universal. Los formularios de script generarán componentes de entrada basados en el bloque param. Los formularios de script admiten automáticamente el progreso y los comentarios.

```
Required?                    false
Position?                    named
Default value                None
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -OutputType

El tipo de salida que devuelve el script. Los valores válidos son: "Text", "Table"

```
Required?                    false
Position?                    named
Default value                Text
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -ShowBackButton

Muestra un botón Volver después de enviar el formulario. Esto solo se utiliza en los formularios de script.

```
Required?                    false
Position?                    named
Default value                False
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### Parámetros comunes

Este cmdlet admite los parámetros comunes: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction, WarningVariable, OutBuffer, PipelineVariable y OutVariable. Para obtener más información, consulte [about\_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216).

### Salidas

### Ejemplos

#### Ejemplo 1: básico

```powershell
New-UDForm -Id 'form1' -Content {
    New-UDTextbox -Id 'form1Textbox' -Label 'Name'
} -OnSubmit {
    Show-UDToast -Message ($EventData.form1Textbox)
}
```

Crea un formulario básico.

#### Ejemplo 2: validación

```powershell
New-UDForm -Id 'form2' -Content {
    New-UDTextbox -Id 'form2Textbox' -Label 'Name'
} -OnSubmit {
    Show-UDToast -Message ($EventData.form2Textbox)
} -OnValidate {
    if ($EventData.form2Textbox -eq 'Bob') {
        New-UDValidationResult -ValidationError 'Bob is not allowed'
    }
    else {
        New-UDValidationResult -Valid
    }
}
```

Crea un formulario con validación.

#### Ejemplo 3: procesamiento

```powershell
New-UDForm -Id 'form3' -Content {
    New-UDTextbox -Id 'form3Textbox' -Label 'Name'
} -OnSubmit {
    Start-Sleep -Seconds 5
    Show-UDToast -Message ($EventData.form3Textbox)
} -OnProcessing {
    New-UDCard -Title 'Processing' -Content {
        New-UDProgress
    }
}
```

Crea un formulario con un cuadro de diálogo de procesamiento.

#### Ejemplo 4: cancelar

```powershell
New-UDForm -Id 'form4' -Content {
    New-UDTextbox -Id 'form4Textbox' -Label 'Name'
} -OnSubmit {
    Show-UDToast -Message ($EventData.form4Textbox)
} -OnCancel {
    Show-UDToast -Message 'Form was cancelled'
}
```

Crea un formulario con un botón de cancelación.

#### Ejemplo 5: texto de envío y cancelación

```powershell
New-UDForm -Id 'form5' -Content {
    New-UDTextbox -Id 'form5Textbox' -Label 'Name'
} -OnSubmit {
    Show-UDToast -Message ($EventData.form5Textbox)
} -SubmitText 'Save' -CancelText 'Close' -OnCancel {
    Show-UDToast -Message 'Form was cancelled'
}
```

Crea un formulario con textos personalizados de envío y cancelación.

#### Ejemplo 6: variante de botón

```powershell
New-UDForm -Id 'form6' -Content {
    New-UDTextbox -Id 'form6Textbox' -Label 'Name'
} -OnSubmit {
    Show-UDToast -Message ($EventData.form6Textbox)
} -ButtonVariant 'contained'
```

Crea un formulario con una variante de botón contained.

#### Ejemplo 7: nombre de clase

```powershell
New-UDForm -Id 'form7' -Content {
    New-UDTextbox -Id 'form7Textbox' -Label 'Name'
} -OnSubmit {
    Show-UDToast -Message ($EventData.form7Textbox)
} -ClassName 'my-form'
```

Crea un formulario con un nombre de clase CSS personalizado.

#### Ejemplo 8: esquema

```powershell
New-UDForm -Id 'form8' -Schema @{
    title = "Test Form"
    type = "object"
    properties = @{
       name = @{
           type = "string"
       }
       age = @{
           type = "number"
       }
    }
} -OnSubmit {
    Show-UDToast -Message ($EventData.name)
    Show-UDToast -Message ($EventData.age)
}
```

Crea un formulario con un esquema. Puede obtener más información sobre JSON Schema aquí: <https://rjsf-team.github.io/react-jsonschema-form/docs/>

#### Ejemplo 9: esquema de interfaz de usuario

```powershell
New-UDForm -Id 'form9' -Schema @{
    title = "Test Form"
    type = "object"
    properties = @{
       name = @{
           type = "string"
       }
       age = @{
           type = "number"
       }
    }
} -uiSchema @{
	"ui:order" = @('age','name')
} -FormData @{ Name = "adam"; Age = 38 } -OnSubmit {
    Show-UDToast -Message ($EventData.name)
}
```

Crea un formulario con un esquema y un esquema de interfaz de usuario. Puede obtener más información sobre JSON Schema aquí: <https://rjsf-team.github.io/react-jsonschema-form/docs/>

#### Ejemplo 10: script

```powershell
New-UDForm -Id 'form10' -Script "Script1.ps1" -OutputType "Table"
```

Crea un formulario a partir de un script. Los parámetros del script definirán el formulario. La salida del script se mostrará en una tabla.

#### Ejemplo 11

```powershell
New-UDForm -Id 'form11' -Content {
   New-UDTextbox -Id 'form11Textbox' -Label 'Name'
} -OnSubmit {
    Show-UDToast -Message ($EventData.form11Textbox)
}
New-UDButton -Text "A submit button outside the form" -OnClick {
    Invoke-UDForm -Id "form11"
}

Invoke-UDForm|Creates a form with a submit button outside the form.
```

#### Ejemplo 12

```powershell
New-UDForm -Id 'form12' -Content {
   New-UDTextbox -Id 'form12Textbox' -Label 'Name'
} -OnSubmit {
    Show-UDToast -Message ($EventData.form12Textbox)
} -OnValidate {
    if ($EventData.form12Textbox -eq 'Hello') {
        New-UDValidationResult -Valid
    }
    else {
        New-UDValidationResult -ValidationError "Name must be 'Hello'"
    }
}
New-UDButton -Text "Validate form" -OnClick {
    Test-UDForm -Id "form12"
}

Test-UDForm|Creates a form with a validate button outside the form.
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.devolutions.net/powershell-universal/es/comandos-de-powershell/new-udform.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
