AutoCompleteBox and SearchText Clear - silverlight-4.0

This is not a question but my answer to a problem I could not find a solution to on the internet.
I had a problem clearing the SearchText in an MVVM Silverlight application. I could clear clear the SelectedItem and Text but the SearchText was left behind. It is read only and cannot be changed by binding.
Example: AutoCompleteBox with a list of Countries. When the user wants to enter Australia they enter 'au' at this point the list appers with Austria and Australia. The user can then select Australia and move on. At the end of editing they click on a 'Save' button. At this point it is likely that you would want to clear the data forn for entering new data.
Even if you have bindings to the SelectedItem and the Text properties and you set them to 'null' and string.Empty respectively the SearchText property remains and the AutoCompleteBox will not clear but will contain 'au'.

I posted about this all over the internet but could get no answer on the control itself and so I came at it from a different angle which may help someone who ends up frustrated like me.
I am using a Silverlight Navigation template application which uses a NavigationFrame in which to load Silverlight pages. I noticed that if I navigated to another page and returned to my data form the SearchText was cleared. Any values that were bound to properties remained valid, just the SearchText had cleared on all AutoCompleteBoxes. I therefore used the PageConductor method of injecting the NavigationFrame into the ViewModel where I could call the refresh method. I got this method from John Papa's example from the Silverlight Firestarter event , I simply added a Refresh method to the IPageConductor interface so I am now able to call 'PageConductor.Refresh()' which is like reloading the page. I hope this helps someone out there.

var t = ProductCombo.ItemsSource;
ProductCombo.ItemsSource = null;
ProductCombo.Text = string.Empty;
ProductCombo.SelectedValue = null;
//ProductCombo.Text = string.Empty;
ProductCombo.ItemsSource = t;
Try this please.it worked for me

You must clear the property bindeaded to Text inside set part of SelectedItem Binded property, like this:
public string AnalisisText
{
get { return _analisisText; }
set
{
if (_analisisText == value)
{
return;
}
_analisisText = value;
RaisePropertyChanged(AnalisisTextPropertyName);
}
}
public DatosAutoCompletaPedidosDetalleViewDTO AnalisisSelect
{
get { return _analisisSelect; }
set
{
if (_analisisSelect == value)
{
return;
}
_analisisSelect = value;
if (_analisisSelect == null) AnalisisText = "";
RaisePropertyChanged(AnalisisSelectPropertyName);
}
}
So, when you set null to property SelectedItem , the other property will set to "".

The easiest way I've found is to extend the AutoCompleteBox:
public class AutoCompleteBoxClear : AutoCompleteBox
{
public AutoCompleteBoxClear()
{
DataContextChanged += (o, e) =>
{
if (SelectedItem == null)
Text = string.Empty;
};
}
}
Now use your new AutoCompleteBoxClear control in your XAML.
This clears the text only when autocompletebox datacontext changes to null (ie the user clicks add in the dataform.)
Note: I think DataContextChanged is available only in Silverlight 5, but I'd guess that anyone still using Silverlight these days would likely have upgraded by now...

var t = ProductCombo.ItemsSource;
ProductCombo.ItemsSource = null;
ProductCombo.Text = string.Empty;
ProductCombo.SelectedValue = null;
//ProductCombo.Text = string.Empty;
ProductCombo.ItemsSource = t;
Unfotunately this is code-behind and I needed an MVVM solution.

I recently had the same problem with my WPF app. I found out that the solution is not to set the object bound to SelectedItem to null, but to its default value. Took me a while to figure this out. So in your example, it would not be SelectedCountry = null, but SelectedCountry = new SelectedCountry(). In this case the SearchText is cleared also. Check my SO post regarding this matter: Autocompletebox doesn't clear keyboard strokes.

Sure SearchText property is read-only, but we can get the child component of AutoCompleteBox:
var searchText = autoCompBox.GetChildByType<TextBox>(item => item.Name == "Text");
And now we can reset SearchText via Text property of TextBox-component:
if (searchText != null) searchText.Text = string.Empty;
In C# 6.0 it is more laconically:
autoCompBox.GetChildByType<TextBox>(item => item.Name == "Text")?.Text = string.Empty;

Related

Access Controls collection at MVC template level Sitefinity

I need to remove an object from the PageHandler Header Controls collection in my page template.
I can use the below script to do so at the widget view level, however the one I need to remove has not yet been added at that point, so I need to move it right before it's consumed.
The only accessible place for it that I could find is in my template file - right before #Html.Section("head"). I'm trying to remove the default canonical URL for this template only (some crazy routing stuff going on in this site... don't ask).
var pageHandler = this.ViewContext.HttpContext.Handler.GetPageHandler();
foreach (var c in pageHandler.Header.Controls)
{
if (c != null && c is System.Web.UI.HtmlControls.HtmlLink)
{
System.Web.UI.HtmlControls.HtmlLink mylink = (System.Web.UI.HtmlControls.HtmlLink)c;
if (mylink.Attributes["rel"] == "canonical")
{
pageHandler.Header.Controls.Remove(mylink);
}
}
}
When I try to use this in the template file inside the <head> tag pageHandler.Header is null.
1 - Am I accessing this object in the wrong way for this particular template level? If so, what's the proper object reference?
2 - Is it simply not set yet because of some behind-the-scenes page construction order in Sitefinity? If so, where could/should I handle accessing this object?
3 - Something else is going on entirely?
I AM NOT ASKING HOW TO FIX A NULL REFERENCE EXCEPTION
I understand that the object is null and am trying to find where in the Sitefinity viewmodel at this level this data might be found.
The canonical url is set in Page_PreRenderComplete event which fires after your code in the view has executed.
What I would do is create a new widget, e.g. CanonicalUrlRemover.
In its Index method find the Page object and subscribe to its PreRenderComplete event. Then in the event handler remove the canonical url.
public ActionResult Index()
{
var page = HttpContext.CurrentHandler.GetPageHandler();
page.PreRenderComplete += Page_PreRenderComplete;
return new EmptyResult();
}
private void Page_PreRenderComplete(object sender, System.EventArgs e)
{
var page = sender as System.Web.UI.Page;
if (page != null)
{
var headerControls = page.Header.Controls;
foreach (var c in headerControls)
{
if (c != null && c is System.Web.UI.HtmlControls.HtmlLink)
{
System.Web.UI.HtmlControls.HtmlLink mylink = (System.Web.UI.HtmlControls.HtmlLink)c;
if (mylink.Attributes["rel"] == "canonical")
{
headerControls.Remove(mylink);
}
}
}
}
}
Just drop the widget in this particular page template and you are good to go.

UWP - Saving Settings does not work all the time

I've got the following code just copied from here. I want to bind a double value to a xaml slider, get this value from the localsetting every time I navigate to the SettingsPage and everytime the slidervalue gets changed by the user I want it to be saved to localsettings. Here is my code so far:
SettingsPage.xaml.cpp:
Windows::Storage::ApplicationDataContainer^ localSettings = Windows::Storage::ApplicationData::Current->LocalSettings;
SettingsPage::SettingsPage()
{
InitializeComponent();
this->viewModel = ref new SettingsViewModel();
this->DataContext = this->viewModel;
}
void SettingsPage::QSlider_ValueChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::Primitives::RangeBaseValueChangedEventArgs^ e)
{
Windows::Storage::ApplicationDataCompositeValue^ composite =ref new Windows::Storage::ApplicationDataCompositeValue();
bool a = composite->Insert(SETTINGS_TAG_SLIDER_Q, dynamic_cast<PropertyValue^>(PropertyValue::CreateDouble((double)sldQ->Value)));
auto values = localSettings->Values;
bool b = values->Insert(SETTINGS_TAG_SETTINGS_PAGE, composite);
}
SettingsPage.xaml:
<Slider x:Name="sldQ" Margin="15,5,15,0" Value="{Binding SliderQValue}" ValueChanged="Slider_ValueChanged" MaxWidth="300" HorizontalContentAlignment="Left" ></Slider>
SettingsViewModel.cpp:
double SettingsViewModel::SliderQValue::get()
{
Windows::Storage::ApplicationDataContainer^ localSettings = Windows::Storage::ApplicationData::Current->LocalSettings;
ApplicationDataCompositeValue^ composite = safe_cast<ApplicationDataCompositeValue^>(localSettings->Values->Lookup(SETTINGS_TAG_SETTINGS_PAGE));
if (composite != nullptr)
{
if (composite->HasKey(SETTINGS_TAG_SLIDER_Q)) {
double value = safe_cast<IPropertyValue^>(composite->Lookup(SETTINGS_TAG_SLIDER_Q))->GetDouble();
return value;
}
}
return 99;
}
My Problem is that this works exactly once! If I navigate from other pages to SettingsPage, I get slidervalue=99. Then I set it by dragging to e.g. 50. Then I navigat back to other page. From the other page I navigate again to SettingsPage and get slidervalue=50. But doing it once again I get 99 again. So it only works for 1 page navigation-cycle but it should work even if the app is rebooted. What is the problem in my code? Am I understanding something wrong?
I actually solved the problem with the help of this. In my code above I was initializing a new 'ApplicationDateCompositeValue' each time I wanted to write/read it. So with the new method it works like it was planned to do:
OnValueChanged:
Windows::Storage::ApplicationDataContainer^ localSettings = Windows::Storage::ApplicationData::Current->LocalSettings;
auto values = localSettings->Values;
values->Insert(TAG_SLIDER, dynamic_cast<PropertyValue^>(PropertyValue::CreateDouble((double)sldQuality->Value)));
Property::get():
ApplicationDataContainer^ localSettings = ApplicationData::Current->LocalSettings;
auto values = localSettings->Values;
if (localSettings->Values->HasKey(TAG_SLIDER)) {
double value = safe_cast<double>(localSettings->Values->Lookup(TAG_SLIDER));
return value;
}
else
return default_value;

Get all SmartForm items from Ektron 9 in a Taxonomy

I'm using Ektron CMS version 9.0
I have smart form content which is allocated to taxonomies e.g. I might have five smart form content items (all of same) type allocated to a taxonomy, and another three to a different taxonomy:
I need to get all content of a smart form type from a taxonomy:
public IEnumerable<T> GetListOfSmartFormFromTaxonomy<T>(long taxonomyId, bool isRecursive) where T : class
{
// TODO
}
What I have working, based on links below, is this:
public IEnumerable<TaxonomyItemData> GetListOfSmartFormFromTaxonomy(long taxonomyId)
{
TaxonomyItemCriteria criteria = new TaxonomyItemCriteria();
criteria.AddFilter(TaxonomyItemProperty.TaxonomyId, CriteriaFilterOperator.EqualTo, taxonomyId);
TaxonomyItemManager taxonomyItemManager = new TaxonomyItemManager();
List<TaxonomyItemData> taxonomyItemList = taxonomyItemManager.GetList(criteria);
return taxonomyItemList;
}
But this just gets the item's titles and ids, not the smart form data itself.
As an Ektron newbie, I don't know how to get all the items of one Smart Form type using only one call (instead of looping through each item and fetching it by ID which is not efficient)
What have I missed? I am working on this actively today and will post my findings here.
References used so far:
http://reference.ektron.com/developer/framework/Organization/TaxonomyItemManager/GetList.asp
Ektron taxonomy and library items (in v9)
EDIT
Posted my just-got-it-working solution below as an fyi and awarded closest answer as accepted. Thanks everyone for your help. Please chime in with any improvements ;)
I'd recommend using the ContentTaxonomyCriteria with the ContentManager.
long smartFormId = 42;
long taxonomyId = 127;
bool isRecursive = true;
var cm = new ContentManager();
var taxonomyCriteria = new ContentTaxonomyCriteria();
taxonomyCriteria.AddFilter(ContentProperty.XmlConfigurationId, CriteriaFilterOperator.EqualTo, smartFormId);
taxonomyCriteria.AddFilter(taxonomyId, isRecursive);
var content = cm.GetList(taxonomyCriteria);
UPDATE
The ContentData object has a property called XmlConfiguration. When the content is based on a smartform, this property will be non-null and have a positive (non-zero) Id: content[0].XmlConfiguration.Id for example.
I often add an Extension Method to my code that will tell me whether a given ContentData is based on a smart form:
public static class ContentDataExtensions
{
public static bool IsSmartFormContent(this ContentData content)
{
return content != null && content.XmlConfiguration != null && content.XmlConfiguration.Id > 0;
}
}
That way I can take a content (or list of content) and check it very quickly in code to see if it's based on a smartform or not:
foreach (var contentData in contentList)
{
if (contentData.IsSmartFormContent())
{
// Do smart-form stuff here...
}
}
Of course, if your content is coming from the framework api and you used a criteria object that is selecting based on a specific XmlConfigurationId, then in theory you wouldn't have to use that, but it still comes in handy quite often.
I'm not quite sure I understand your organizational structure, but you do have the ability to do your own sub clauses that select directly against the database.
In this case I wouldn't use the TaxonomyItemManager, I would use the ContentManager with a special criteria:
ContentManager cApi = new ContentManager();
var criteria = new ContentCriteria();
criteria.AddFilter(ContentProperty.Id, CriteriaFilterOperator.InSubClause, "select taxonomy_item_id where taxonomy_id = " + taxonomyId);
criteria.AddFilter(ContentProperty.XmlConfigurationId, CriteriaFilterOperator.EqualTo, smartformTypeId);
var yourContent = cApi.GetList(criteria);
That should do what you're asking for (grab the content specifically that is a member of a Taxonomy while only being of a specific SmartForm config). It's worth noting you don't need the second criteria piece (XmlConfigurationId) if your Taxonomy only contains that XmlConfiguration.
For Information, this is what I came up with. Noted Brian Oliver's comment on List but using patterns from other devs, can refactor later.
To clarify, we are creating classes from the XSDs generated from the smart forms, so have smart form types to play with. Your use may be simpler that ours.
public IEnumerable<T> GetListOfSmartFormFromTaxonomy<T>(long taxonomyId, bool isRecursive = false) where T : class
{
long smartFormId = GetSmartFormIdFromType(typeof(T));
// checks here for smartformid=0
ContentManager contentManager = new ContentManager();
ContentTaxonomyCriteria criteria = new ContentTaxonomyCriteria();
// Smart Form Type
criteria.AddFilter(ContentProperty.XmlConfigurationId, CriteriaFilterOperator.EqualTo, smartFormId);
// Taxonomy
criteria.AddFilter(taxonomyId, isRecursive);
List<ContentData> contentDataList = contentManager.GetList(criteria);
IEnumerable<T> smartFormList = ConvertToSmartFormList<T>(pressReleaseDataList);
return smartFormList;
}
private IEnumerable<T> ConvertToSmartFormList<T>(List<ContentData> contentDataList) where T : class
{
List<T> smartFormList = new List<T>();
if (contentDataList != null && contentDataList.Count > 0)
{
foreach (ContentData contentData in contentDataList)
{
if (contentData.IsSmartFormContent())
{
T smartForm = GetDeserializedContent<T>(contentData.Html);
if (smartForm != null)
{
PropertyInfo property = smartForm.GetType().GetProperty("ContentId");
if (property != null)
{
property.SetValue(smartForm, contentData.Id, null);
}
smartFormList.Add(smartForm);
}
}
}
}
return smartFormList;
}
private long GetSmartFormIdFromType(Type smartFormType)
{
SmartFormConfigurationManager manager = new SmartFormConfigurationManager();
SmartFormConfigurationCriteria criteria = new SmartFormConfigurationCriteria();
// Note: Smart Form Title must match the type's name, i.e. no spaces, for this to work
criteria.AddFilter(SmartFormConfigurationProperty.Title, CriteriaFilterOperator.EqualTo, smartFormType.Name);
List<SmartFormConfigurationData> configurationData = manager.GetList(criteria);
if (configurationData == null || configurationData.Count == 0)
{
return 0;
}
return configurationData.First().Id;
}

My Nintex Custom Action not reading in Workflow Variable in SingleLineInput

I've written a custom workflow action that takes in several values, mostly using the SingleLineInput control.
When I assign literal values, I have no issues, but when I try to assign a Workflow Variable, I don't get the actual value of the variable, I get the literal text - something like {WorkflowVariable:XmlValue} - assuming my variable was names XmlValue.
I'm not sure what I could possibly be doing wrong. Any ideas?
Here's code snippets:
The javascript for retrieving the value from the SingleLineInput
function TPAWriteConfig() {
configXml.selectSingleNode("/NWActionConfig/Parameters/Parameter[#Name='FieldValue']/PrimitiveValue/#Value").text = getRTEValue('<%=fieldValue.ClientID%>');
SaveErrorHandlingSection();
return true;
}
The server control:
<Nintex:ConfigurationProperty ID="ConfigurationProperty3" runat="server" FieldTitle="Field Value" RequiredField="True">
<TemplateControlArea>
<Nintex:SingleLineInput runat="server" id="fieldValue"></Nintex:SingleLineInput>
</TemplateControlArea>
</Nintex:ConfigurationProperty>
From my adapter class:
private const string FieldValueProperty = "FieldValue";
NWActionConfig config = new NWActionConfig(this);
config.Parameters[2] = new ActivityParameter();
config.Parameters[2].Name = FieldValueProperty;
config.Parameters[2].PrimitiveValue = new PrimitiveValue();
config.Parameters[2].PrimitiveValue.Value = string.Empty;
config.Parameters[2].PrimitiveValue.ValueType = SPFieldType.Text.ToString();
From the activity class:
public static DependencyProperty FieldValueProperty = DependencyProperty.Register("FieldValue", typeof (string),
typeof (
WriteOnePdfFieldActivity));
public string FieldValue
{
get { return (string) GetValue(FieldValueProperty); }
set { SetValue(FieldValueProperty, value); }
}
I feel a little silly answering my own question, but for the sake of anyone else having the same issues. Here's how it works:
If you're putting a literal value in the field, just use the value
If you're using any other kind of assignment, do a lookup based on the value.
The code below demonstrates:
var fieldValue = FieldValue.StartsWith("{") ? ctx.AddContextDataToString(FieldValue, true) : FieldValue;
This extract the value from the workflow context. Hope this helps.

GXT TextField or TextArea not decode html entites

i use grid cell renderer... and form bindig...
grid cell renderer valus is good
form bindig value is bad (
i tested: ff9 and last chrome
this bug ? or browser error ? or something else ?
sorry i little speak english.... (i use gtranslate)
error picture => http://test.eggproject.hu/gxt/textfieldentitesbugg.PNG
about json(gxt model)
{"ID":1,"user_email":"xxxx#xxxx.com","display_name":"XXX YYYY","user_cegnev":"","user_jogosultsag":"administrator","user_kedvezmeny":0,"user_city":0,"user_irsz":-1,"user_district":3,"user_street":241,"user_hazszam":"2813","user_emelet":"10","user_ajto":"588","user_kapucsengo":"58","user_comment":"óüöú\u0151\u0171áí","first_name":"Harangozo","last_name":"Gabor","user_telephone":"06111111","user_street2":""}
user_comment error displaying just textarea or textfield why ?
This is due to the components each section is using. A grid is essentially a tag which means any HTML encoded data loaded into this table is rendered correctly. Conversely A TextBox is a tag which only displays exactly what can be seen.
A solution is a custom field binding which processes the data in and out.
public class HTMLParserBinding extends FieldBinding {
protected Field<?> field;`
public HTMLParserBinding( Field<?> field, String property ) {
super(field, property);
this.field = field;
}
protected Object onConvertFieldValue( Object value ) {
if (value == null) {
return null;
}
return Format.htmlDecode(value.toString());
}
protected Object onConvertModelValue( Object value ) {
if( value == null ) {
return null;
}
return Format.htmlEncode(value.toString());
}
}