Skip to content

Commit e236ae2

Browse files
dimodidimodi
authored andcommitted
docs(mediaquery): Replace obsolete Form Integration demo
1 parent 43f25ec commit e236ae2

File tree

1 file changed

+136
-6
lines changed

1 file changed

+136
-6
lines changed

components/mediaquery/integration.md

Lines changed: 136 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,142 @@ You can resize the Chart based on the browser size and re-render with the new di
191191

192192
## Form Integration
193193

194-
You can utilize the Form Columns to fit the contents of the Telerik Form to a smaller browser window. You can find an example in the <a href="https://github.com/telerik/blazor-ui/tree/master/form/responsive-form" target="_blank">Responsive Form</a> demo application.
194+
You can use the MediaQuery component to set various [layout-related parameters of the Form component]({%slug form-overview%}#form-parameters), such as `Orientation`, `Columns`, `ColumnSpacing`, and `ButtonsLayout`.
195+
196+
>caption Responsive Form with MediaQuery
197+
198+
````CSHTML
199+
@using System.ComponentModel.DataAnnotations
200+
201+
<ul>
202+
<li>
203+
<code>IsSmallScreen</code>: <strong>@IsSmallScreen</strong>
204+
</li>
205+
<li>
206+
<code>IsMediumScreen</code>: <strong>@IsMediumScreen</strong>
207+
</li>
208+
<li>
209+
<code>IsLargeScreen</code>: <strong>@IsLargeScreen</strong>
210+
</li>
211+
<li>
212+
<code>IsExtraLargeScreen</code>: <strong>@IsExtraLargeScreen</strong>
213+
</li>
214+
</ul>
215+
216+
<TelerikForm Model="@Employee"
217+
ButtonsLayout="@FormButtonsLayout"
218+
Orientation="@FormOrientation">
219+
<FormValidation>
220+
<DataAnnotationsValidator></DataAnnotationsValidator>
221+
<TelerikValidationSummary />
222+
</FormValidation>
223+
<FormItems>
224+
<FormGroup LabelText="Personal Information" Columns="@FormGroupColumns" ColumnSpacing="@FormGroupColumnSpacing">
225+
<FormItem Field="@nameof(Person.FirstName)" LabelText="First Name"></FormItem>
226+
<FormItem Field="@nameof(Person.MiddleName)" LabelText="Middle Name"></FormItem>
227+
<FormItem Field="@nameof(Person.LastName)" LabelText="Last Name"></FormItem>
228+
<FormItem Field="@nameof(Person.BirthDate)" LabelText="Birth Date"></FormItem>
229+
<FormItem Field="@nameof(Person.Address)" EditorType="@FormEditorType.TextArea" ColSpan="@FormGroupColumns"></FormItem>
230+
</FormGroup>
231+
<FormGroup LabelText="Work Information" Columns="@FormGroupColumns" ColumnSpacing="@FormGroupColumnSpacing">
232+
<FormItem Field="@nameof(Person.Id)" LabelText="Corporate ID" Enabled="false"></FormItem>
233+
<FormItem Field="@nameof(Person.HireDate)" LabelText="Hire Date"></FormItem>
234+
<FormItem Field="@nameof(Person.Team)"></FormItem>
235+
<FormItem Field="@nameof(Person.LeaveDate)" LabelText="Leave Date"></FormItem>
236+
</FormGroup>
237+
</FormItems>
238+
</TelerikForm>
239+
240+
<TelerikMediaQuery Media="@SmallScreenMediaQuery" OnChange="@( (bool matches) => { IsSmallScreen = matches; ConfigureForm(); } )" />
241+
<TelerikMediaQuery Media="@MediumScreenMediaQuery" OnChange="@( (bool matches) => { IsMediumScreen = matches; ConfigureForm(); } )" />
242+
<TelerikMediaQuery Media="@LargeScreenMediaQuery" OnChange="@( (bool matches) => { IsLargeScreen = matches; ConfigureForm(); } )" />
243+
<TelerikMediaQuery Media="@ExtraLargeScreenMediaQuery" OnChange="@( (bool matches) => { IsExtraLargeScreen = matches; ConfigureForm(); } )" />
244+
245+
@code {
246+
private Person Employee { get; set; } = new() { Id = 1234 };
247+
248+
private FormOrientation FormOrientation { get; set; } = FormOrientation.Vertical;
249+
private FormButtonsLayout FormButtonsLayout { get; set; } = FormButtonsLayout.Start;
250+
private int FormGroupColumns { get; set; } = 1;
251+
private string FormGroupColumnSpacing { get; set; } = string.Empty;
252+
253+
private string SmallScreenMediaQuery { get; set; } = "(max-width: 430px)";
254+
private string MediumScreenMediaQuery { get; set; } = "(min-width: 431px)";
255+
private string LargeScreenMediaQuery { get; set; } = "(min-width: 768px)";
256+
private string ExtraLargeScreenMediaQuery { get; set; } = "(min-width: 1199px)";
257+
258+
private bool IsSmallScreen { get; set; }
259+
private bool IsMediumScreen { get; set; }
260+
private bool IsLargeScreen { get; set; }
261+
private bool IsExtraLargeScreen { get; set; }
262+
263+
private void ConfigureForm()
264+
{
265+
if (IsMediumScreen)
266+
{
267+
FormOrientation = FormOrientation.Horizontal;
268+
FormButtonsLayout = FormButtonsLayout.Center;
269+
FormGroupColumns = 2;
270+
FormGroupColumnSpacing = "1em";
271+
}
272+
273+
if (IsSmallScreen)
274+
{
275+
FormOrientation = FormOrientation.Vertical;
276+
FormButtonsLayout = FormButtonsLayout.Stretch;
277+
FormGroupColumns = 1;
278+
FormGroupColumnSpacing = string.Empty;
279+
}
280+
281+
if (IsLargeScreen)
282+
{
283+
FormOrientation = FormOrientation.Vertical;
284+
FormButtonsLayout = FormButtonsLayout.Start;
285+
FormGroupColumns = 3;
286+
FormGroupColumnSpacing = "2em";
287+
}
288+
289+
if (IsExtraLargeScreen)
290+
{
291+
FormOrientation = FormOrientation.Vertical;
292+
FormButtonsLayout = FormButtonsLayout.End;
293+
FormGroupColumns = 4;
294+
FormGroupColumnSpacing = "3em";
295+
}
296+
}
297+
298+
public class Person
299+
{
300+
public int Id { get; set; }
301+
302+
[Required]
303+
public string FirstName { get; set; } = string.Empty;
304+
305+
[Required]
306+
public string MiddleName { get; set; } = string.Empty;
307+
308+
[Required]
309+
public string LastName { get; set; } = string.Empty;
310+
311+
[Required]
312+
public string Address { get; set; } = string.Empty;
313+
314+
[Required]
315+
public DateTime? BirthDate { get; set; }
316+
317+
[Required]
318+
public DateTime HireDate { get; set; } = DateTime.Today;
319+
320+
[Required]
321+
public string? Team { get; set; }
322+
323+
public DateTime? LeaveDate { get; set; }
324+
}
325+
}
326+
````
195327

196328
## See Also
197-
198-
* [Live Demo: MediaQuery - Grid Integration](https://demos.telerik.com/blazor-ui/mediaquery/grid-integration)
199-
* [Overview]({%slug mediaquery-overview%})
200-
* [Events]({%slug mediaquery-events%})
201329

202-
330+
* [Live Demo: MediaQuery and Grid Integration](https://demos.telerik.com/blazor-ui/mediaquery/grid-integration)
331+
* [MediaQuery Overview]({%slug mediaquery-overview%})
332+
* [MediaQuery Events]({%slug mediaquery-events%})

0 commit comments

Comments
 (0)