I am trying to get the selected element in Ckeditor. I.e. if the html is:
This has a link.
I want to retrieve the entire a element when I select the link text.
As I understand it the following code:
editor.getSelection().getSelectedElement()
is supposed to do that. But it is always returning null (no matter how much or how little I select). I have tried various other element types and the result is always the same.
getSelection() by itself is not returning null. I am able to get just the link text with
editor.getSelection().getNative().toString().
I even tried some old code that I found here:
http://cksource.com/forums/viewtopic.php?f=6&t=11997&p=31833
but that resulted in the error Object #<Object> has no method 'getRangeAt'
Does anyone have any suggestions?
I was too troubleshooting the same thing. But got this code working.
Just check if it helps
var element = CKEDITOR.plugins.link.getSelectedLink( editor );
if ( element )
{
if ( element.is( 'a' ) )
{
var urldata = element.getAttribute( 'href' );
this.setValue(urldata);
}
}
Related
I'm trying to dynamically build an action link for adding items to a database in Laravel. The problem is that I need to pass a parameter with category_id, which I only get after selecting the category in html select element.
I thought about using the even onChange() on select element, and then building up the link in js function, and finally setting it to "a" element with the help of js selector. However this approach doesn't work.
var link = "{{ action('ItemController#create', [ 'id' =>"+selectedId.value+"]) }}";
document.getElementById("AddItemLink").href = link;
Is producing: http://localhost:8000/item/create/+selectedId.value+
What I need to get is: http://localhost:8000/item/create/8
If I do console.log(selectedId.value), the output is correct - 8.
Any ideas how to deal with this?
You can do that,
var link = "/item/create/"+ selectedId.value;
document.getElementById("AddItemLink").href = link;
I am trying to do simple upsert to the array field based on branch condition. However branch does not accept a reql expression as argument and I get error Expected type SELECTION but found DATUM.
This is probably some obvious thing I've missed, however I can't find any working example anywhere.
Sample source:
var userId = 'userId';
var itemId = 'itemId';
r.db('db').table('items').get(itemId).do(function(item) {
return item('elements').default([]).contains(function (element) {
return element('userId').eq(userId);
}).branch(
r.expr("Element already exist"),
//Error: Expected type SELECTION but found DATUM
item.update({
elements: item('elements').default([]).append({
userId: 'userId'
})
})
)
})
The problem here is that item is a datum, not a selection. This happens because you used r.do. The variable doesn't retain information about where the object originally came from.
A solution that might seem to work would be to write a new r.db('db').table('items').get(itemId) expression. The problem with that option is the behavior isn't atomic -- two different queries might append the same element to the 'elements' array. Instead you should write your query in the form r.db('db').table('items').get(itemId).update(function(item) { return <something>;) so that the update gets applied atomically.
i have a little problem and canĀ“t figure out how to resolve it.
I am Validating an XDocument against a schema and i get all the nodes which have error. But the Validation process doesnt go deeper after finding an error.
_document.Validate(_schema, (o, e) =>
{
XElement xEle = null;
if (o is XAttribute)
xEle = (o as XAttribute).Parent;
if (o is XElement)
xEle = o as XElement;
if (xEle == null)
{
Debug.WriteLine(o.ToString());
return;
}
_elemtList.Add(o as XElement);
});
My problem is like following
<Car>
<CarName></CarName>
<CarInteriour>
<CarInteriorColor>Red</CarInteriorColor>
</CarInteriour>
</Car>
Lets say this is valid.
If i Change the following to
<Car>
<CarInteriour>
<CarInteriorColor></CarInteriorColor>
</CarInteriour>
</Car>
Here is the CarName tag missing and the color Red.
I will only get the error for CarName but not color Red.
The validation process seems to skip that structure because it did find an error.
Is there a way to still keep validating even if there was an error ?
Ok i found a solution which works for me and i am giving you an update because it works pretty neat.
What i am doing now is. I use a foreach for every XElement in my _document.Descendants() and i validate every element. This finds every error in the document multiple times.
So what i do is, i check my errorlist if i already did find this error before. My errorlist is a list of my own class errorcontainer which has the found XElement with the Error Message.
This way i only add new errors to the list and show this errors on a dialog. The user now can select an error and i will directly jump to the error in my editor.
ErrorContainer errorContainer = new ErrorContainer(xEle, e.Message);
if (_errors.Any(error => error.xElement.Equals(errorContainer.xElement) && string.CompareOrdinal(error.errorMessage, errorContainer.errorMessage) == 0))
{
return;
}
_errors.Add(errorContainer);
I hope this helps some other people who need help on this issue :)
LINQ newbie here
I am trying to get a value of a field - using a fieldName variable.
If I do a watch on row[FieldName] I do get a value - but when I do it on the actual code it will not compile.
string fieldName = "awx_name"
List<awx_property> propertyQry =
(
from property in crm.awx_propertyawx_properties
where property.awx_propertyid == new Guid(id)
select property
).ToList();
foreach (awx_property row in propertyQry)
{
//THIS DOES NOT WORK
fieldValue = row[fieldName];
}
Thanks in advance. Alternatives would be welcome as well
You keep us guessing what you are trying to do here... You need to specify the types of the objects, so it's easy for us to understand and help. Anyway, I think you are trying to get an object based on the ID. Since you are getting by Id, my guess would be the return value is a single object.
var propertyObj =( from property in crm.awx_propertyawx_properties
where property.awx_propertyid == new Guid(id)
select property
).SingleOrDefault();
if(propertyObj != null) {
fieldValue = propertyObj.GetType().GetProperty(fieldName).GetValue(propertyObj, null);
}
Of course, you need to add validation to make sure you don't get null or any other error while accessing the property value.
Hope it helps.
What type is fieldValue? What does awx_property look like? This will only work is awx_property is a key/value collection. It its not, you could use reflection instead.
If it is a key/value collection you are probably missing a cast. (row[FieldName].ToString() or something) Also you are missing a semi-colon in the foreach block.
I've got Webgrid sourced to a EF4 entity with navigation properties (basically relationships)
If the webgrid encounters a null for that foreign key it errors out because it's looking for that object, which in this case doesn't exist.
Is it possible to catch when a column item is null and default to a value within the Webgrid helper?
I guess the follwoing code should serve your purpose if I am correctly relating to your problem. Below Trigger is the navigated entity which we will get by include in linq and we can put a check like below when this entity is null.
grid.Column("Job", format: #<text> #if (#item.Trigger !=null) { <span> Write your default code here .</span> } </text> close text tag here ),
Hope that solves your problem.
I noticed after posting 'text' is getting truncated in this forum so put text in < and > between 2 # as you can see and also close that text tag before the final ).
All the best.