javascript focus() not working from tab1 to tab2 in primefaces - javascript

I am using functionality where if validation error comes then goto link is generating an id of required component with focus() on the top of the page. On click of that link the required component is highlighted. Now its working if error is in same tab. But first tab is active focus function not pointing the required text box inside third tab.
void encodeGotoLabel(FacesContext context, UIComponent component, ResponseWriter writer,
FacesMessage msg) throws IOException {
String id = getid(context, msg);
if (id != null && !FacesMessage.SEVERITY_INFO.equals(msg.getSeverity())
&& !FacesMessage.SEVERITY_FATAL.equals(msg.getSeverity())) {
String inputLabel = findInputLabel(context, id);
if (inputLabel != null) {
ResourceBundle bundle ="bundle";
writer.writeText(" (", null);
writer.writeText(bundle.getString("goTo") + " ", null);
writer.startElement("a", component);
writer.writeAttribute("href", "javascript:document.getElementById('" + id
+ "').focus();",
null);
writer.writeText(inputLabel, null);
writer.endElement("a");
writer.writeText(")", null);
}
}
}

This function loops on a group of tabs and check if there is an error, if so it switch to it and focus on the required field, all you need to do is add it in your function :
var tabs = PF('tabViewWv').getLength(); //tabViewWv is WidgetVar name
for (var iter = 1; iter <= tabs ; iter++) {
if ($('#form\\:tabView\\:tab' + iter).find(':input').hasClass('ui-state-error')) {
PF('tabViewWv').select(iter - 1);
return false;
}
}

Related

Checkbox Check changed event firing twice C#

I have a listview with checkbox. According to my requirement I uncheck through javascript. But because of that script my Checkchanged event fires twice and returns the previous unchecked(through javascript) value on second time fires.
Also usually any operation check box triggers an event. But if you check the same item which is unchecked through javascript just before is not fires the checkedchanged event.
I am not sure why is it happening when using script.
Please find the code below
JavaScript
function CallConfirmBox() {
alert("456");
if (confirm('Schedule more than one time slot for the same day will overwrite the file')) {
return true;
}
else {
var id = document.getElementById('<%= hdnValue.ClientID%>').value;
alert(id);
$('#' + id).attr('checked', false);
alert("123")
id = "";
return false;
}
}
CodeBehind
protected void chkCheck_CheckedChanged(object sender, EventArgs e)
{
CheckBox chkCheck = (CheckBox)sender;
ListViewItem item = (ListViewItem)chkCheck.NamingContainer;
ListViewDataItem dataItem = (ListViewDataItem)item;
string lookupId = lvLookup.DataKeys[dataItem.DisplayIndex].Value.ToString();
hdnValue.Value = chkCheck.ClientID;
if (lookupMstVal == "ScheduledTime." && lbCheckedIdList.Items.Count > 0 && chkCheck.Checked)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "CallConfirmBox", "CallConfirmBox();", true);//" + chkCheck.ClientID + "
}
if (chkCheck.Checked)
lbCheckedIdList.Items.Add(lookupId);
else
lbCheckedIdList.Items.Remove(lookupId);
hdfLookupId.Value = "";
foreach (ListItem itm in lbCheckedIdList.Items)
{
hdfLookupId.Value += (hdfLookupId.Value == "" ? "" : ",") + itm.Value;
}
postbackFlag = true;
}
Please Help! Thanks.

Microsoft Dynamics CRM 2011/2013

In my entity (A) has 50 option set. If the user select 10 optionsset value and not selected remaining one, and he/she click save button. In that situation i need to alert user "To fill all the option set". I don't want to get the Schema name for the optionset individually, i need to get all the option set schema name dynamically.
Is it possible? Help me.
I have not tested this function, but you can try this and make changes if needed.
function IsFormValidForSaving(){
var valid = true;
var message = "Following fields are required fields: \n";
Xrm.Page.data.entity.attributes.forEach(function (attribute, index) {
if (attribute.getRequiredLevel() == "required") {
if(attribute.getValue() == null){
var control = attribute.controls.get(0);
// Cheking if Control is an optionset and it is not hidden
if(control.getControlType() == "optionset" && control.getVisible() == true) {
message += control.getLabel() + "\n";
}
valid = false;
}
}
});
if(valid == false)
{
alert(message);
}
}
Ref: Microsoft Dynamics CRM 2011 Validate required form javascript
Required fields individual alert fire before the on save event. If you wish to prevent the single alert routine for all unfilled option sets you need to remove the requirement constraint and manage the constraint yourself, probably in your on save handler. I’m just writing the idea here (not tested).
// enter all optionsets ids
var OptionSets50 = ["new_optionset1","new_optionset2","new_optionset50"];
var dirtyOptions = [];
function MyOptionSet(id) {
var mos = this;
var Obj = Xrm.Page.getAttribute(id);
var Ctl = Xrm.Page.getControl(id);
Obj.addOnChange(
function () {
if (Obj.getValue() != null)
delete dirtyOptions[id];
else
dirtyOptions[id] = mos;
});
this.GetLabel = function() {
return Ctl.getLabel();
}
if (Obj.getValue() == null)
dirtyOptions[id] = mos;
}
function OnCrmPageLoad() {
for(var x in OptionSets50) {
OptionSets50 [x] = new MyOptionSet(OptionSets50 [x]);
}
Xrm.Page.data.entity.addOnSave(OnCrmPageSave);
}
//check for dirty options and alert
function OnCrmPageSave(execContext) {
var sMsg = "The following Optinsets Are Required: ";
var sLen = sMsg.length;
for(var os in dirtyOptions) {
sMsg += dirtyOptions[os].GetLabel() + "\n";
}
if (sMsg.length > sLen) {
execContext.getEventArgs().preventDefault();
alert(sMsg);
}
}

Refresh ContentPlaceHolder using javascript

My webapp (written in ASP.NET) is laid out with MasterPages. In the content area of the Masterpage, the is an iframe that I display the pages. On navigation click I simple set the ContentUrl (within the contentplaceholder) to a new url and it refreshes the content area.
Here is the method that does that:
Protected Sub radprojecttree_NodeClick(sender As Object, e As Telerik.Web.UI.RadTreeNodeEventArgs) Handles radprojecttree.NodeClick
Dim ts As String = e.Node.Attributes("contentpage")
radpancontentholder.ContentUrl = ts
If (Not SiteUser Is Nothing) Then
BSRMaster.navtree.NavTree_InitNodes(Nothing, e.Node)
End If
End Sub
But was I also need is to set the ContentUrl within javascript at certain times and show the page. However when I set the ContentUrl the page does not show. how do I refresh the contentplaceholder in javascript?
Here is the code that I have for javascript so far:
function goToPage(){
var strLoc = "";
switch (AutoExpandOption) {
case "RestoreLastNode" :
strLoc = readCookie(strUser + 'LastPageLocation');
if ((typeof(strLoc) == "undefined") || (strLoc == null)) {
strLoc = 'Secure/TaskManager.aspx';
createCookie(strUser + 'LastPageLocation', 'TaskManager.aspx', 100);
}
break;
case "GoToTaskManager" :
strLoc = 'Secure/TaskManager.aspx';
break;
case "GoToDashboard" :
strLoc = 'Secure/Dashboards.aspx';
break;
}
if (strLoc != "") {
var ph = $find('ctl00_radpancontentholder');
ph._contentUrl = strLoc;
//document.getElementById('pagecontentframe').src = strLoc;
}
}
$find was being called before the page loaded fully, therefore no controls were present

Javascript - How to enable/disable text input in IE9

The following script worked in IE8 but not in IE9:
function toggleSelect(fieldName)
{
var idx = fieldName.lastIndexOf("_");
var sub = fieldName.substring(19,idx);
if (document.findForm["cb_Row_PageAutoDelete_" + sub].checked) {
document.findForm["SHIP_QTY_" + sub].disabled=false ;
} else {
document.findForm["SHIP_QTY_" + sub].disabled=true ;
}
return true;
}
I can display the value of the SHIP_QTY field so I know it's on the page but the disable function does not work.
Thanks for your help.
If findForm is the name of the form, you want window.findForm rather than document.findForm. You can also just use the result of the other field's checked property directly rather than an if/else. So your code changes to:
function toggleSelect(fieldName)
{
var idx = fieldName.lastIndexOf("_");
var sub = fieldName.substring(19,idx);
window.findForm["SHIP_QTY_" + sub].disabled = window.findForm["cb_Row_PageAutoDelete_" + sub].checked;
return true;
}

contextmenu in webbrowser Windows Phone 7

i successfully added a contextmenu to my webbrowser with this javascript code:
public void AttachContextMenu()
{
try
{
if ((App.Current as App).Browser.IsScriptEnabled)
{
(App.Current as App).Browser.InvokeScript("execScript", "function FindParentLink(item) \r\n{\r\n\tif (!item.parentNode)\r\n\t\treturn null;\r\n\tif (item.tagName.toLowerCase() == 'a') \r\n\t{\r\n\t\treturn item;\r\n\t} \r\n\telse \r\n\t{\r\n\t\treturn FindParentLink(item.parentNode);\r\n\t}\r\n}\r\n\r\nfunction FindParentImage(item) \r\n{\r\n\tif (!item.parentNode)\r\n\t\treturn null;\r\n\tif (item.tagName.toLowerCase() == 'img') \r\n\t{\r\n\t\treturn item;\r\n\t} \r\n\telse \r\n\t{\r\n\t\treturn FindParentImage(item.parentNode);\r\n\t}\r\n}\r\n\r\nfunction HandleContextMenu() \r\n{\r\n\tvar linkItem = FindParentLink(event.srcElement);\r\n var imageItem = FindParentImage(event.srcElement);\r\n var notifyOutput = '';\r\n if (linkItem != null) if (linkItem.href != null) notifyOutput += linkItem.href;\r\n if (imageItem != null) if (imageItem.src != null) notifyOutput += imageItem.src;\r\n if (notifyOutput != '')\r\n window.external.notify(notifyOutput);\r\n else\r\n\t\twindow.external.notify('NOTLINKIMG');\r\n}");
(App.Current as App).Browser.InvokeScript("execScript", "document.oncontextmenu = HandleContextMenu;");
}
}
catch
{
}
}
this method is used everytime the browser navigated.
So, the scriptnotify code, which will be used when the user holds a link :
if (e.Value.ToString() != null && IsValidUri(e.Value.ToString()))
{
ContextMenu cm = new ContextMenu();
MenuItem menuItem0 = new MenuItem() { Header = "X", Tag = e.Value };
menuItem0.Click += new RoutedEventHandler(X_Click);
MenuItem menuItem1 = new MenuItem() { Header = "Y", Tag = e.Value };
menuItem1.Click += new RoutedEventHandler(Y_Click);
MenuItem menuItem2 = new MenuItem() { Header = "Z", Tag = e.Value };
menuItem2.Click += new RoutedEventHandler(Z_Click);
cm.Items.Add(menuItem0);
cm.Items.Add(menuItem1);
cm.Items.Add(menuItem2);
ContextMenuService.SetContextMenu(Browser, cm);
cm.IsZoomEnabled = false;
cm.VerticalOffset = mouseClickPosition.Y;
cm.IsOpen = true;
}
so far, i hope i made everything right.
now, it randomly works. nearly 50% of tries cause a error, Visual studio navigates to a blue-white frame named "No source available" and throws a NullReferenceException.
Where should this be solved? already set a try-catch block around the hole 2 method, no change :/
hope you have some ideas
greets
roqstr
don't got it working, but there's a workaround:
AttachContextMenu()
-> holding a link will push the url to the scriptnotify method.
build a custom contextmenu & everything is fine.

Categories

Resources