WPF-Forge/Forge.Forms

Visibility based on radio buttons

hashitha opened this issue ยท 11 comments

In the following case, is there any way we can make the textview visible only if we select the first option

  <select
    name="CalculateDates"
    defaultValue="LMP"
    as="radiobuttons"
    label="Select">
    <option
      value="LMP date:">LMP</option>
    <option
      value="EDD date:">EDD</option>
  </select>


<textarea  
        type="string"
        name="Comments"
        label="EDD comments"></textarea>

maybe we can base the visibility on the selected index?

textarea isvisible="{Binding CalculateDates|???}"

I have to think about the converter part. It's unfortunate that binding expressions dont support converter arguments. Maybe we should add that to the grammar.

Something like
{Binding CalculateDates|IsEqual('LMP')}

I think {Binding CalculateDates|IsEqual('LMP')} will work well

We should be able to chain these, i.e.

{Binding Gender|NotEqual('F')} && ({Binding CalculateDates|IsEqual('LMP')} || {Binding CalculateDates|IsEqual('ABC')})

Maybe we can re-use the stuff that @edongashi did for Environment Variables.

Anywhere that you have a bool you can create custom expressions like that one, so this already works. We only need to implement converter parameters for better reusability.

Converters can now have a parameter using the following syntax:

|IsEqual('String')
|IsEqual(3)
|IsEqual(25.3)
|IsEqual(true)
|IsEqual(false)
|IsEqual(null)

The IsEqual is just a demonstration. You can create custom factories and register them in Resource.ValueConverterFactories. You cannot have a dynamic value in converters.

Note This is not Binding.ConverterParameter that is passed to IValueConverter.Convert. It was too messy and too late to implement it. Instead, the parameter is parsed from the expression and is passed to corresponding factory in the new property: Resource.ValueConverterFactories, which creates a new converter with the parameter value baked in.

For backwards compatibility we now have two dictionaries for storing converters globally:

Resource.ValueConverters is a dictionary of string : IValueConverter and Resource.ValueConverterFactories is a dictionary of string : func(object -> IValueConverter).

Feel free to register custom converters at application startup.

I have tested this and it works well on Textview and datetime but I can't get this to work on <text> field

text visible="false" does not seem to work. I will see what's wrong

It is the same with Heading tag

fixed in 42e23e2 for all non-input elements

This is working well now