I would like to be able to use the Telerik window component within my forms... for example, a field where you select a person from a database - but finding that person is a complicated search - so instead of a dropdown, it's a display only field that has an ellipsis button next to it, and it would open a window, where they would find a person, select the person, and then pass back the selection to the main form.
But the telerik blazor window doesn't seem to render within the scope of the form that you nest it under, so the containing EditContext is not available, and I have tried everything I can think of to get the data back from the window and update the main form data behind the scenes, but the EditContext still doesn't know about the change.
Example Below (3 files)
FormTest.razor:
@page "/formtest/"
@using SMS5.BApp.Classes
<
CascadingValue
Value
=
"@MyStuff"
>
<
div
class
=
"sms-tab-content"
>
<
EditForm
EditContext
=
"@StuffForm"
@
key
=
"@("
FormEditCtx1")">
<
div
>MAIN FORM:</
div
>
<
div
>
SomeStuff1: <
InputText
@
bind-Value
=
"@MyStuff.SomeStuff1"
></
InputText
>
SomeStuff2: <
InputText
@
bind-Value
=
"@MyStuff.SomeStuff2"
></
InputText
>
</
div
>
<
div
>Component Containing Window:</
div
>
<
WindowTest2
OnChanged
=
"@StuffGotUpdated"
></
WindowTest2
>
</
EditForm
>
<
div
>
<
div
>Log of changes to form context:</
div
>
<
textarea
@
bind
=
"@Log"
cols
=
"150"
rows
=
"20"
></
textarea
>
</
div
>
</
div
>
</
CascadingValue
>
@code {
protected EditContext StuffForm { get; set; }
public Stuff MyStuff = new Stuff() { SomeStuff1="foo", SomeStuff2="bar"};
public string Log { get; set; }
protected override void OnInitialized()
{
StuffForm = new EditContext(MyStuff);
StuffForm.OnFieldChanged += EditContext_OnFieldChanged;
}
private void EditContext_OnFieldChanged(object sender, FieldChangedEventArgs e)
{
// code to save goes here
var x = e.FieldIdentifier.FieldName;
Log += "--" + x +" changed.--";
StateHasChanged();
}
protected void StuffGotUpdated()
{
StateHasChanged();
}
}
WindowTest2.razor:
@using SMS5.BApp.Classes
<
div
>
<
div
>
<
TelerikButton
OnClick
=
"@OpenWin"
>
Open Window
</
TelerikButton
>
</
div
>
<
div
>
<
div
>In window component, outside of window, from cascading parameter:</
div
>
Some Stuff 1:<
InputText
@
bind-Value
=
"@MyStuff.SomeStuff1"
></
InputText
>
Some Stuff 2:<
InputText
@
bind-Value
=
"@MyStuff.SomeStuff2"
></
InputText
>
</
div
>
</
div
>
<
TelerikWindow
Top
=
"50px"
Left
=
"100px"
Visible
=
"@IsVisible"
>
<
WindowTitle
>
<
strong
>The Title</
strong
>
</
WindowTitle
>
<
WindowActions
>
<
WindowAction
Name
=
"Minimize"
/>
<
WindowAction
Name
=
"Maximize"
/>
<
WindowAction
Name
=
"Close"
/>
</
WindowActions
>
<
WindowContent
>
<
div
>
<
input
@
bind-value
=
"@SomeStuff1Local"
/> (local var copied to and back from SomeStuff1)
</
div
>
<
div
>
<
input
@
bind-value
=
"@MyStuff.SomeStuff2"
/> (direct bind to MyStuff.SomeStuff2)
</
div
>
<
TelerikButton
OnClick
=
"@CloseWin"
>
Close Window
</
TelerikButton
>
</
WindowContent
>
</
TelerikWindow
>
<
TelerikButton
OnClick
=
"@InvokeCallback"
>
Refresh All
</
TelerikButton
>
@code {
[CascadingParameter] public Stuff MyStuff { get; set; }
[Parameter] public EventCallback<
string
> OnChanged { get; set; }
public bool IsVisible { get; set; } = false;
public string SomeStuff1Local { get; set; }
protected void OpenWin()
{
IsVisible = true;
SomeStuff1Local = MyStuff.SomeStuff1;
StateHasChanged();
}
protected void CloseWin()
{
IsVisible = false;
MyStuff.SomeStuff1 = SomeStuff1Local;
StateHasChanged();
}
protected void InvokeCallback()
{
OnChanged.InvokeAsync("blah");
}
protected override void OnInitialized()
{
}
}
Stuff.cs:
namespace SMS5.BApp.Classes
{
public class Stuff
{
public string SomeStuff1 { get; set; }
public string SomeStuff2 { get; set; }
}
}
p.s. I am still working of a reproducible example for the grid inline editing with EF proxy issue, it is going to take a little while to get that together.
Thanks
Portia