how to set an element to be required webmethods caf using javascript - webmethods

I want to set required=true of an input in caf webmethods using javascript.
this my code that I try to set required:
if (CAF.model('#{activePageBean.clientIds['dropDowntypeFlux']}').getValue() == 'expo'){
CAF.model('#{activePageBean.clientIds['htmlInputMatricule']}').setAttribute("required", "true");
}
but it does not work.

Try using CAF.model().element to get the original HTML Element:
if (CAF.model('#{activePageBean.clientIds['dropDowntypeFlux']}').element.getValue() == 'expo'){
CAF.model('#activePageBean.clientIds['htmlInputMatricule']}').element.setAttribute("required", "true");
}
With CAF.model() you are using a JavaScript CAF Object with other features.

Related

How to change dir property of the Angular CDK overlay at runtime?

I'm using Angular 10, on click the following function is executed to preform direction change:
private changeHtmlDirection(direction: 'rtl' | 'ltr') {
document.getElementsByTagName("html")[0].dir = direction;
}
It works well, only that the Angular CDK does not update.
I tried to find an API to change Angular CDK's direction at runtime, but couldn't find any.
I saw that there's a BidiModule but it uses only to get the current direction rather than set it.
Is there any solution?
According to the material documentation, you can't change 'dir' on the "html" tag so that affects bidi API. You can see the document at the following link:
bi-directionality document
But if you want to use material bi-directionality you can add the 'dir' directive to a container element in the root component like bellow:
<div [dir]="documentDirection"> </div>
and whenever the 'documentDirection' variable changes, the bidi "change emitter" will be emit.
like following code you can subscribe to it:
constructor(
private dir: Directionality ) {
this.isRtl = dir.value === 'rtl';
this.dir.change.subscribe(() => {
this.isRtl = !this.isRtl;
});
}

Angular 4 Execute Function when html fully loaded

I have a problem with asynchronous HTTP calls in Angular 4 using typescript/components... I create an array of objects, and in the HTML I have checkboxes next to the objects. Now I want certain objects to be checked, by executing a function in angular. However when I do
(document.getElementById(id) as HTMLInputElement).checked = true;
In my component.ts.
It can't find the element however when I do the same code in a function that executes when you push a button it works. So the problem is that the HTML is not fully loaded when I execute the function. How can I make sure the HTML is fully loaded?
Yeah You shouldn't be manipulating the DOM.
Tag your HTML element in the html using hash.
<input ... #inputname />
Retrieved in the ts controller component.
#ViewChild('inputname') theinput;
Check after view init. ngAfterViewInit if it is checked
ngAfterViewInit() {
...
(this.form as HTMLInputElement).checked
...
}
Consider this as the last option since I wouldn't recommend direct DOM manipulation in Angular. But if you are still facing the issue, use can use my solution as a work around.
In constructor ,
let interval = setInterval(() => {
let flag = self.checkFunction();
if (flag)
clearInterval(interval);
}, 100)
Now create the function
checkFunction() {
if(document.getElementById(id)){
(document.getElementById(id) as HTMLInputElement).checked = true;
return true;
}
return false;
}

Selenium assert has class

I have an element with a known id. I want to assert or verify that it has a specific class.
The HTML of the element is:
<a id="SearchList" class="something-else disabled"></a>
I want to use the id "SearchList" to locate the element and then verify that it has the class "disabled".
EDITS:
I am using the Selenium IDE a FireFox addon.
verifyElementPresent | css=a[id='SearchList'][class*='disabled'] |
This doesn't help you for the IED, but in C# I can do this using the GetAttribute method.
var allClasses = webElement.GetAttribute("class");
var elementHasClass = allClasses.Split(' ').Any(c => string.Equals("classLookingFor", c, StringComparison.CurrentCultureIgnoreCase));
You could use getAttribute() method to get the attribute and verify that. I assume you use Java for your scripts.
WebElement list = driver.findElement(By.id("SearchList"));
String disabled = list.getAttribute("disabled");
if(disabled.equals("disabled")){
// something
}else{
// something else
}
Sorry for necroposting. I have some addition to what #Purus suggested.
As "disabled" is part of a class name class="something-else disabled", list.getAttribute("disabled") will return null. My suggestion to do it in the following way (Selenium WebDriver Java client):
WebElement element= driver.findElement(By.id("SearchList"));
String elementClass= element.getAttribute("class");
if(elementClass != null && elementClass.contains("disabled")){
// something
}else{
// something else
}

ASP.NET control rendering HTML attributes

I have a custom control in an ASP.NET Web Forms project that inherits from System.Web.UI.Control.
I want to add attributes in the markup that to not correspond to properties of that control e.g.
<myControls:Hyperlink runat=server custom-client-side-attr="1"></<myControls:Hyperlink>
The problem I am having is that the exception
Type 'myControls.Hyperlink' does not have a public property named
'custom-client-side-attr'.
I have tried PersistChildren(false), but that does not fix it. It has been a while since I have been in the depths of ASP.NET Web Forms and cannot remember how this is done.
You have to add those in server-code:
hl1.Attributes["custom-client-side-attr"] = "1";
You can still do it in the markup - you'd have to do it prior to the the declaration:
<% hl1.Attributes["custom-client-side-attr"] = "1"; %>
<myControls:Hyperlink ID="hl1" runat=server custom-client-side-attr="1"></<myControls:Hyperlink>
If you want an attribute like this, you have to create a property in for the user control. You may use viewstate or hidden control to keep the property persistent. Your code may look something like this:
public string custom_client_side_attr
{
get {
if (ViewState["custom_client_side_attr"] != null)
{
return ViewState["custom_client_side_attr"].ToString();
}
return string.Empty;
}
set
{
ViewState["custom_client_side_attr"] = value;
//set custom atribute for the hyperlink here
}
}
And access the property through markup:
<myControls:Hyperlink id="myCustomControl" runat=server custom_client_side_attr="1"></<myControls:Hyperlink>
or in the code:
myCustomControl.custom_client_side_attr="1";
If your custom control derives from WebControl it seems to work as you want.

Forced to use template?

This code from Dart worries me:
bool get isTemplate => tagName == 'TEMPLATE' || _isAttributeTemplate;
void _ensureTemplate() {
if (!isTemplate) {
throw new UnsupportedError('$this is not a template.');
}
...
Does this mean that the only way I can modify my document is to make it html5?
What if I want to modify an html4 document and set innerHtml in a div, how do I achieve this?
I am assuming you are asking about the code in dart:html Element?
The method you are referring to is only called by the library itself, and only in methods where isTemplate has to be true, for example this one. If you follow this link, you can also read what other fields/methods work like this.
innerHtml is a field in every subclass of Element which supports it, for example DivElement
Example:
DivElement myDiv1 = new DivElement();
myDiv1.innerHtml = "<p>I am a DIV!</p>";
query("#some_div_id").innerHtml = "<p>Hey, me too!</p>";