Ewl » Canonical The canonical version of EWL Read More
Clone URL:  
Pushed to 2 repositories · View In Graph Contained in tip and canonical

Created form-control extension creators for checkboxes and radio buttons.

Changeset cb77a27c698b

Parent baade3275984

by Profile picture of William GrossWilliam Gross

Changes to one file · Browse files at cb77a27c698b Showing diff from parent baade3275984 Diff from another changeset...

 
411
412
413
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
414
415
416
 
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
@@ -411,6 +411,180 @@
  }     /// <summary> + /// Creates a checkbox for this data value. + /// </summary> + /// <param name="dataValue"></param> + /// <param name="label">The checkbox label. Do not pass null. Pass an empty collection for no label.</param> + /// <param name="setup">The setup object for the checkbox.</param> + /// <param name="value"></param> + /// <param name="additionalValidationMethod"></param> + public static Checkbox ToCheckbox( + this DataValue<bool> dataValue, IReadOnlyCollection<PhrasingComponent> label, CheckboxSetup setup = null, bool? value = null, + Action<Validator> additionalValidationMethod = null ) { + return new Checkbox( + value ?? dataValue.Value, + label, + setup: setup, + validationMethod: ( postBackValue, validator ) => { + dataValue.Value = postBackValue.Value; + additionalValidationMethod?.Invoke( validator ); + } ); + } + + /// <summary> + /// Creates a checkbox for this data value. + /// </summary> + /// <param name="dataValue"></param> + /// <param name="label">The checkbox label. Do not pass null. Pass an empty collection for no label.</param> + /// <param name="setup">The setup object for the checkbox.</param> + /// <param name="value"></param> + /// <param name="additionalValidationMethod"></param> + public static Checkbox ToCheckbox( + this DataValue<decimal> dataValue, IReadOnlyCollection<PhrasingComponent> label, CheckboxSetup setup = null, decimal? value = null, + Action<Validator> additionalValidationMethod = null ) { + var boolValue = new DataValue<bool> { Value = ( value ?? dataValue.Value ).DecimalToBoolean() }; + return boolValue.ToCheckbox( + label, + setup: setup, + additionalValidationMethod: validator => { + dataValue.Value = boolValue.Value.BooleanToDecimal(); + additionalValidationMethod?.Invoke( validator ); + } ); + } + + /// <summary> + /// Creates a flow checkbox for this data value. + /// </summary> + /// <param name="dataValue"></param> + /// <param name="label">The checkbox label. Do not pass null. Pass an empty collection for no label.</param> + /// <param name="setup">The setup object for the flow checkbox.</param> + /// <param name="value"></param> + /// <param name="additionalValidationMethod"></param> + public static FlowCheckbox ToFlowCheckbox( + this DataValue<bool> dataValue, IReadOnlyCollection<PhrasingComponent> label, FlowCheckboxSetup setup = null, bool? value = null, + Action<Validator> additionalValidationMethod = null ) { + return new FlowCheckbox( + value ?? dataValue.Value, + label, + setup: setup, + validationMethod: ( postBackValue, validator ) => { + dataValue.Value = postBackValue.Value; + additionalValidationMethod?.Invoke( validator ); + } ); + } + + /// <summary> + /// Creates a flow checkbox for this data value. + /// </summary> + /// <param name="dataValue"></param> + /// <param name="label">The checkbox label. Do not pass null. Pass an empty collection for no label.</param> + /// <param name="setup">The setup object for the flow checkbox.</param> + /// <param name="value"></param> + /// <param name="additionalValidationMethod"></param> + public static FlowCheckbox ToFlowCheckbox( + this DataValue<decimal> dataValue, IReadOnlyCollection<PhrasingComponent> label, FlowCheckboxSetup setup = null, decimal? value = null, + Action<Validator> additionalValidationMethod = null ) { + var boolValue = new DataValue<bool> { Value = ( value ?? dataValue.Value ).DecimalToBoolean() }; + return boolValue.ToFlowCheckbox( + label, + setup: setup, + additionalValidationMethod: validator => { + dataValue.Value = boolValue.Value.BooleanToDecimal(); + additionalValidationMethod?.Invoke( validator ); + } ); + } + + /// <summary> + /// Creates a radio button for this data value. + /// </summary> + /// <param name="dataValue"></param> + /// <param name="group">The group of which this radio button will be a part. Do not pass null.</param> + /// <param name="label">The radio button label. Do not pass null. Pass an empty collection for no label.</param> + /// <param name="setup">The setup object for the radio button.</param> + /// <param name="value"></param> + /// <param name="additionalValidationMethod"></param> + public static Checkbox ToRadioButton( + this DataValue<bool> dataValue, RadioButtonGroup group, IReadOnlyCollection<PhrasingComponent> label, RadioButtonSetup setup = null, bool? value = null, + Action<Validator> additionalValidationMethod = null ) { + return group.CreateRadioButton( + value ?? dataValue.Value, + label, + setup: setup, + validationMethod: ( postBackValue, validator ) => { + dataValue.Value = postBackValue.Value; + additionalValidationMethod?.Invoke( validator ); + } ); + } + + /// <summary> + /// Creates a radio button for this data value. + /// </summary> + /// <param name="dataValue"></param> + /// <param name="group">The group of which this radio button will be a part. Do not pass null.</param> + /// <param name="label">The radio button label. Do not pass null. Pass an empty collection for no label.</param> + /// <param name="setup">The setup object for the radio button.</param> + /// <param name="value"></param> + /// <param name="additionalValidationMethod"></param> + public static Checkbox ToRadioButton( + this DataValue<decimal> dataValue, RadioButtonGroup group, IReadOnlyCollection<PhrasingComponent> label, RadioButtonSetup setup = null, + decimal? value = null, Action<Validator> additionalValidationMethod = null ) { + var boolValue = new DataValue<bool> { Value = ( value ?? dataValue.Value ).DecimalToBoolean() }; + return boolValue.ToRadioButton( + group, + label, + setup: setup, + additionalValidationMethod: validator => { + dataValue.Value = boolValue.Value.BooleanToDecimal(); + additionalValidationMethod?.Invoke( validator ); + } ); + } + + /// <summary> + /// Creates a flow radio button for this data value. + /// </summary> + /// <param name="dataValue"></param> + /// <param name="group">The group of which this radio button will be a part. Do not pass null.</param> + /// <param name="label">The radio button label. Do not pass null. Pass an empty collection for no label.</param> + /// <param name="setup">The setup object for the flow radio button.</param> + /// <param name="value"></param> + /// <param name="additionalValidationMethod"></param> + public static FlowCheckbox ToFlowRadioButton( + this DataValue<bool> dataValue, RadioButtonGroup group, IReadOnlyCollection<PhrasingComponent> label, FlowRadioButtonSetup setup = null, + bool? value = null, Action<Validator> additionalValidationMethod = null ) { + return group.CreateFlowRadioButton( + value ?? dataValue.Value, + label, + setup: setup, + validationMethod: ( postBackValue, validator ) => { + dataValue.Value = postBackValue.Value; + additionalValidationMethod?.Invoke( validator ); + } ); + } + + /// <summary> + /// Creates a flow radio button for this data value. + /// </summary> + /// <param name="dataValue"></param> + /// <param name="group">The group of which this radio button will be a part. Do not pass null.</param> + /// <param name="label">The radio button label. Do not pass null. Pass an empty collection for no label.</param> + /// <param name="setup">The setup object for the flow radio button.</param> + /// <param name="value"></param> + /// <param name="additionalValidationMethod"></param> + public static FlowCheckbox ToFlowRadioButton( + this DataValue<decimal> dataValue, RadioButtonGroup group, IReadOnlyCollection<PhrasingComponent> label, FlowRadioButtonSetup setup = null, + decimal? value = null, Action<Validator> additionalValidationMethod = null ) { + var boolValue = new DataValue<bool> { Value = ( value ?? dataValue.Value ).DecimalToBoolean() }; + return boolValue.ToFlowRadioButton( + group, + label, + setup: setup, + additionalValidationMethod: validator => { + dataValue.Value = boolValue.Value.BooleanToDecimal(); + additionalValidationMethod?.Invoke( validator ); + } ); + } + + /// <summary>   /// Creates a block checkbox for this data value.   /// </summary>   /// <param name="dataValue"></param>