Toggle SlateJS editor's readonly props - slatejs

I am playing with SlateJS v0.34.5. Is there any way to toggle Editor readonly state?

I have figured out. So silly of me. adding readOnly property in state and then in Editor passing it as follows
<Editor readonly={this.state.readOnly} />
Then doing regular setState stuff for toggling it.

Related

Custom ToggleButton in Xamarin.Android

I am working on a MvvmCross based android app. The app contains (among other things) a large number of ToggleButton(s). The buttons are added in .axml files. Their Checked property and Click event are bound to view-model properties. Since the Checked property of the each ToggleButton should reflect the state of some property on a application server, I don't want their checked state to be changed when the user clicks them, but only when the bound property on the view-model is changed. An example how this "special" toggle button should work: When the user clicks it, the "Checked" property of the button does not change only the ICommand to which the click event is bound to is invoked. The method invoked by the command in turn changes the value of the property on the view-model(if executed successfully). Extending a ToggleButton in WPF or Windows Forms to described functionality is easy but I don't know how to do that in android. Any ideas will appreciated.
Uroš
I found the solution to my problem. It seems it had to do something with the way I set up the bindings for my ToggleButton
MyToggleButton was implemented as:
public sealed class MyToggleButton : ToggleButton, View.IOnClickListener
{
public MyToggleButton(Context context, IAttributeSet attrs)
: base(context, attrs)
{
SetOnClickListener(this);
}
public void OnClick(View v)
{
Checked = !Checked;
}
}
As you can see I just set the Checked property back to previous value when ever the user clicks the button. In the asmx I use the following block to add the button.
<controls.MyToggleButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
local:MvxBind="Checked Value;Click ClickCommand" />
As it turns out the problem with described solution is that the OnClick(View v) method is not executed when the user clicks the button as long as the .axms file contains binding to Click event. I have no idea why that is so I would love any explanation. The workaround I used is to define custom event in the derived class, raise the custom event in the OnClick event handler and than bind to that event.
Uros

Composite Component and setPropertyActionListener

I have a composite component that have a dialog...
Inside the dialog I have the following piece of code:
<p:commandButton id="selectButton" icon="ui-icon-check" oncomplete="lookupDialog.hide();" update=":#{cc.clientId}:#{cc.attrs.fieldId}_panelGrid">
<f:setPropertyActionListener target="#{cc.attrs.targetValue}" value="#{entity}" />
</p:commandButton>
So, when the button is clicked, the dialog vanishes, but the property isn´t set.
There is no errors, no warnings, nothing! So I simply don´t know what is happening...
If you need anymore details, please just say so! :)
***EDIT
This is a related question, but not really what I want to do...
Pass Argument to a composite-component action attribute
I just need the propertyActionListener to work.
Here some extra information:
<cc:attribute name="targetValue" required="true"/>
the value:
targetValue="#{acaoController.entity.responsavel}"
Where inside the bean (acaoController)
I have an entity...
And inside the entity I have another object, that is "responsavel".
Try checking setters and getters of responsavel getting called when you close the dialog box.
Otherwise you can use Flash to pass on the value between components. In the action method of command button,
Flash flash = FaceUtil.getFacesContext().getExternalContext().getFlash();
flash.put("entity",entity);
And you can extract the value like this:
Flash flash = FaceUtil.getFacesContext().getExternalContext().getFlash();
responsavel = (Responsavel) flash.get("entity");

hide an attribute initially at startup in web application

I am working on a JSF application.
I have recently faced a problem, that how to hide any attribute at the start-up of the application.
For Example -
I have a h:panelGrid attribute for displaying table, but I want to show this table only when a checkbox is clicked, Here I am able to made it working for show/hide but only from second time onwards.
What I want is to hide this table using h:panelGrid when application loads this view, the later part as I told I have achieved.
It would be grateful if somebody cite it for general hide at start-up.
Thanks.
Create a boolean attribute in the ManagedBean which this page uses and set it to false (for example in PostConstruct method). Then use it as a rendered attribute of your <h:panelGrid> and it's going to be defaultly hidden.
let's say
#ManagedBean
#RequestScoped
public class Bean {
private boolean visible = false;
//setters and getters
}
//later on page
<h:panelGrid rendered="#{bean.visible} />
I got it...somehow like this
in panelGrid set style="visibility:hidden"
and in checkBox, call javascript function and in there set
if (show)
{
obj.style.display = "block";
obj.style.visibility="visible";
}
else
{
obj.style.display = "none";
}
It does the trick.
Thanks Petr for help.

PrimeFaces Ajax Listener not executed when process attribute is specified for a different component

When I specify process attribute of p:ajax tag, the listener is not executed. If I omit the process attribute, then the listener is called as expected.
Here is the view snippet:
<p:messages id="messages" />
<h:inputText id="inputToProcess" value="#{controller.inputToProcess}" />
<p:selectBooleanCheckbox id="testCheckbox" >
<p:ajax event="change" process="inputToProcess"
update="messages #this inputToUpdate"
listener="#{controller.processChecked}" />
</p:selectBooleanCheckbox>
<h:inputText id="inputToUpdate" value="#{controller.inputToUpdate}" />
And Controller:
#javax.faces.bean.ManagedBean
#javax.faces.bean.ViewScoped
public class Controller implements Serializable {
private String inputToProcess;
private String inputToUpdate;
//getters and setters
public void processChecked(javax.faces.AjaxBehaviorEvent e) {
// doing some stuff here
}
}
I attached a phaseListener to a view with ANY_PHASE PhaseId, and here is what I observed.
When I specify process attribute , the value of the inputToProcess input is successfully set to the controller during the Update Model phase (no exception occurs). Then the Invoke Application and Render Response phases are executed, but no listener is called. One thing I noticed is that checkbox is not set in the end. But, there are no conversion or validation errors, because as I said the Update Model and Invoke Application phases are executed.
If I omit process attribute, here is what I see: the listener is normally called during the Invoke Application phase (since immediate is false by default), and then `Render Response is executed. Checkbox is successfully set.
Is there any explanation for this sort of behavior?
It should work fine at first sight. At least, it works fine that way when using standard JSF components. I'd bet it to be a bug or "feature" of PrimeFaces that it doesn't process the action when the action component is not included in the process. Adding #this to process should solve it. Consider posting an issue report to PrimeFaces guys.
Further, I'd rather use event="valueChange" or event="click" instead of event="change" or just remove the event altogether, it defaults to the right value already (valueChange which will render onclick in checkbox and radio button components). The change event works differently in MSIE for checkboxes and radiobuttons. It's only triggered on 2nd click and forth. You don't want to be browser dependent.
As per your comment:
The problem with the standard JSF checkbox and ajax components, is that the listener is invoked during Process Validations phase, but I need to update the model first!
This is not true. Probably you was using valueChangeListener instead of <f:ajax listener> or confusing the one with the other. The <f:ajax listener> is always invoked during invoke action phase.

How to Implement the ICommand as DependencyProperty

I am using the implementation give at Bind TextBox on Enter-key press to handle the enter key for text box.
But I am using MVVm pattern for my application. Therefore I have defined the ICommand handler in my VieModel class. I want to bind it to view.
The sample application uses
InputBindingsManager.UpdatePropertySourceWhenEnterPressed="TextBox.Text"
and I want to use
InputBindingsManager.UpdatePropertySourceWhenEnterPressed="{Binding myCommandHandler}"
instead.
Can anybody suggest what modification are required in the code?
You can go for inputbindings for a textbox. in this you can bind a Icommand object to command property ok keybindings
Here is the sample code
<TextBox Text="{Binding Firstname, UpdateSourceTrigger=PropertyChanged}">
<TextBox.InputBindings>
<KeyBinding Key="Enter" Command="{Binding ValidationCommand}">
</KeyBinding>
</TextBox.InputBindings>
</TextBox>

Resources