I am using the standard RichTextColumns.cs helper class that is added by VS2012's default Metro Style project template. It uses the RichTextBlock internally to add RichTextColumns. DataBinding is working fine with the following markup
<common:RichTextColumns>
<common:RichTextColumns.ColumnTemplate>
<DataTemplate>
<RichTextBlockOverflow Width="400" Margin="50,0,0,0"/>
</DataTemplate>
</common:RichTextColumns.ColumnTemplate>
<RichTextBlock Width="400">
<Paragraph>
<Run Text="{Binding Content}"/>
</Paragraph>
</RichTextBlock>
Now I have the embedded hyperlinks in 'Content' that are not treated as hyperlinks in WinRT. I need them to behave like hyperlinks. So I want to retrieve the text that's getting bound to the RichTextBlock, tokenize it, insert InlineUI elements that have the HyperlinkButton at appropriate places. Now I could do all this if I could only retrieve the text that is getting bound to the RichTextBlock. Unfortunately I can't seem to 'retrieve' it.
I tried
RichTextBlock value = (RichTextBlock)GetValue(RichTextContentProperty);
valueRun = (Run)((Paragraph)value.Blocks[0]).Inlines[0];
value.Select(((Paragraph)value.Blocks[0]).ContentStart, ((Paragraph)value.Blocks[0]).ContentEnd);
Paragraph para = TokenizeTweet(value.SelectedText);
But the SelectedText is always empty.
However if I do a
value.Blocks.Clear()
it clears out the text that is getting bound. What am I missing?
Simply put, how to retrieve unformatted text from a RichTextBlock in WinRT (Not WPF or Silverlight).
Thanks and Regards,
Sumit.
Instead of trying to retrieve it, why not simply use a converter on the binding?
Related
I am trying to write a control that takes a list of names, allows the user to select from this list and then posts back the username for the name that has been selected.
Firstly, I used a Syncfusion ejDropDownList control to accomplish this, where the code I used was:
<ej-drop-down-list id="UserList" datasource="(IEnumerable<User>)ViewBag.Users" ej-for="Username">
<e-drop-down-list-fields text="Name" value="Username" />
</ej-drop-down-list>
This works fine and when I submit the form, the Username field is bound correctly in the associated model.
Since there are too many names in the list to realistically use a drop-down list, an autocomplete control is preferable.
However, when I implemented the control in the following manner:
<ej-autocomplete id="UserList" datasource="(IEnumerable<User>)ViewBag.Users" ej-for="Username" filter-type="Contains">
<e-autocomplete-fields text="Name" value="Username" />
</ej-autocomplete>
Then the 'Username' value in the model is bound to the 'Name' field.
Is anyone familiar with Syncfusion controls who can tell me how I can bind the selected value (as opposed to the selected text) to the 'Username' column successfully?
Thanks,
Sean
Syncfusion Autocomplete not have a field type of value. You can also use Key field for your scenario.<ej-autocomplete id="UserList" datasource="(IEnumerable<User>)ViewBag.Users" ej-for="Username" filter-type="Contains">
<e-autocomplete-fields text="Name" key="Username" />
</ej-autocomplete>
refer the documentation link: https://help.syncfusion.com/aspnetmvc/autocomplete/data-binding
If I have a Command Object such as
class AppContactInfoCommand {
String fname = "Tom";
}
When I pass that command object to my view to populate my form I have to do this
<g:textField name="cmd.fname" value="${cmd.fname}"/>
This just seems extremely repetitive and time consuming if I have large forms with many fields. Isn't there any way to to have the g:textField intelligently detect that value and auto-populate the value field so all I have to do is
<g:textField name="cmd.fname" />
Other frameworks I have worked with do this so Im sure there must be a way from Grails to do this too.
Grails Version: 3.1
There is nothing stopping you from writing your own tag library to do just that. However the included tag libraries for such things as the textField do not have this behavior. As can be seen from the documentation.
In the past I have built labels for my form like this:
<label wicket:for="name"><wicket:label><wicket:message key="name"></wicket:message></wicket:label>:</label><input wicket:id="name" type="text"/>
Do I still need to use the wicket:label tag? I am not using wicket:label in wicket 7 and it seems to work fine. I may not be understanding the purpose of using wicket:label. It seems like wicket:label is just additional markup. Below is what I am doing now. Is this correct?:
<label wicket:for="name"><wicket:message key="name"></wicket:message>:</label><input wicket:id="name" type="text"/>
This example is related to Wicket XHTML tags
Have a look at the JavaDoc of AutoLabelResolver and AutoLabelTextResolver.
The <label wicket:for="name"> is handled by AutoLabelResolver. It links the HTML label tag to the HTML form component (in your case the input tag) by filling in the correct ID in the HTML for attribute of the label. It also adds css classes to the label tag for for example errors, so you can style the text in the label tag in case of an error.
The <wicket:label> has two purposes. If you give it a value either by the key attribute (as you did) or by having some text between the tags, the text is set as the label model of the Java FormComponent, which then is used in validation messages like this '${label}' is required. (see LabeledWebMarkupContainer#setLabel and LabeledWebMarkupContainer#getLabel).
If you don't assign any text to the <wicket:label> tag, then it is used as output. That means the value of the label model of your Java FormComponent is used to replace the tag.
If you have no <wicket:label> in the HTML markup and no label model set in your Java code, then your Java FormComponent will have an empty label model and Wicket falls back to using the Wicket ID as label. So depending on how your Wicket IDs look, you will get validator messages like 'user_name' is required. instead of something nice looking like 'User name' is required.
I'm trying to set a class or id parameter on a <h:inputHidden> in JSF. The code looks like this:
<h:inputHidden value="#{getData.name}" class="targ" />
But in the browser, the class isn't set:
<input type="hidden" name="j_idt6" value="j_idt6">
I need to set a class to this parameter, because I have a JavaScript autocomplete function for a <h:inputText> that sets a value in the hidden input, which needs to be passed in the next page.
Any ideas? Thanks!
I know it's a little bit late, but it can help someone in the future.
As inputHidden shows nothing in the browser there's no sense to allow it to have a class.
You can use the Id but as the Id could change as you change the component parents using it would bring some headache.
I'd suggest as a workaround, you can give it a parent so you can manipulate it by javascript.
Exemple:
JSF
<h:panelGroup styleClass="someCssClass">
<h:inputHidden id="someId" value="someValue" />
</h:panelGroup>
Javascript (using jQuery, you could use pure javascript also)
$('.someCssClass input[type=hidden]').val('yourNewValue');
None of these answers here satisfied my needs (need the PrimeFaces component, need class not ID, wrapping is too much work), so here's what I came up with:
Use pass-through attributes: https://www.primefaces.org/jsf-2-2-pass-through-attributes
Use pass:hidden-class="blah" (in my case, it's xmlns:pass up top)
Use [attribute=value] selector:
https://www.w3schools.com/cssref/sel_attribute_value.asp
document.querySelector multiple data-attributes in one element
That basically boils down to using something like this (because h:inputHidden becomes a regular input): document.querySelector("input[hidden-class=" + blah + "]")
Please, see similar question - How can I know the id of a JSF component so I can use in Javascript
You can sed "id" property, but in final html code it can be not the same, but composite: for example, if your input with id="myhidden" is inside form with id="myform", final input will have id="myform:myhidden".
In the end, I used a standard HTML <input type="hidden"> tag, as I had no advantages for using the JSF one. If you're trying to set a value in a hidden input with JavaScript, I recommend using this workaround.
<textbox id="nextTitleTextbox" readonly="true" value="#bind(ivm.inventory.successorTitleName)" />
<button id="nextTitleButton" label="..." mold="trendy" onClick="#command('chooseFormerOrSuccessor', isFormer = false)"/>
<a id="nextTitleHrefView" href="/inventory_new.do?method=edit&docUID=${ivm.inventory.successorTitleName}">view</a>
<a id="nextTitleHrefHistory" href="javascript:showRenamingHistory(${ivm.inventory.successorTitleName},${ivm.inventory.successorTitleName})">history</a>
The problem is in 'a' tags. Textbox and buttons works fine, but links in 'a' tags do not catch information from binding, so link there looks like /inventory_new.do?method=edit&docUID=. I really don't understand what's wrong here, because I tried a lot of combination and something similar is working on other pages. Where is mistake in this binding?
I even tried to put string from zscript
<zscript>
String successorTitleHref = "/inventory_new.do?method=edit&docUID=" + ivm.inventory.successorTitleName;
</zscript>
But got exception:
Typed variable declaration : Class or variable not found: ivm.inventory.replacementTitleName.
Also, it's supported controls, that locates in separate file, and every control adding with use derective.
Binding in ZK has nothing to do with variable replacement. #bind() doesn't mean you can use ${...}. The two are completely separate concepts even though both are called "EL Expression" in the manual. But binding EL Expression and ZUML EL Expressions are two different things.
To allow access to ivm in a zscript, you need to define this variable somewhere in the script. One way is to instantiate it:
IVM ivm = new IVM();
or you can use a custom variable resolver.