tiwood
April 7, 2020, 8:09pm
1
Hi,
is it possible to set the value of my text field based on a query parameter?
dashboard.com/?email=foobar@baz.io
should set the value of my Email
text input to foobar@baz.io
.
I’ve tried using Invoke-UDJavaScript
with document.getElementById("Email").value = 'foobar@baz.io';
which actually sets the text but in the submit the value itself is empty.
New-UDInput -Id "Form" -SubmitText "Continue" -Validate -Content {
New-UDInputField -Type 'textbox' -Name 'Email' -Placeholder 'E-Mail'
} -Endpoint {}
Hello @tiwood I developed a component called New-UDField it is right here to download:-
https://marketplace.universaldashboard.io/Dashboard/UniversalDashboard.UDField
The repo for this module is here:- https://github.com/psDevUK/UD-Field
The 2nd example in the readme shows how to set values of the fields based on an input. I hope this answers your question, as I know this would work. Peace
tiwood
April 8, 2020, 6:07pm
3
Hi, thanks for your Input!
I’ve opted for the following solution:
#// functions.ps1
function ConvertReferer-ToQueryStrings {
param (
[Parameter(Mandatory)]
[string]
$Referer
)
$hashtable = New-Object hashtable
$Referer -split "\?" | Where-Object { $_ -like "*=*"} | ForEach-Object { $_ -split "&" } | ForEach-Object {
$kv = $_ -split "="
$k = $kv[0]
$v = $kv[1]
$null = $hashtable.Add($k, $v)
}
return $hashtable
}
#// dashboard.ps1
New-UDColumn -Size 6 -Endpoint {
if ($request.Headers["referer"]) {
$queryStrings = ConvertReferer-ToQueryStrings -Referer $request.Headers["referer"]
if ($queryStrings["email"]) {
$EmailPreset = $queryStrings["email"]
} else {
$EmailPreset = $null
}
New-UDInput -Id "Form" -SubmitText "Next" -Content {
New-UDInputField -Type 'textbox' -Name 'Email' -Placeholder 'E-Mail' -DefaultValue $EmailPreset
} -Endpoint ([scriptblock]::Create((Get-Content -Path "$($dashboardRoot)/endpoints/RedeemInvite.ps1" -Raw)))
}
}