Mootools: get text from clicked link's sibling table node - select

here's the situation:
| ID | Name | ...
+----+--------+---
| 12 | Henry | ... a whole list of names, ids,&c ...you get the idea
+----+--------+---
| 13 | Julia | ...
+-------------+---
...
all the names are links. when selected, they load the rest of the table for editing by passing the name into a quick mysql query. but since i'm getting dupes, i need to grab the id as well to pass along. i also need it for updating the corrected (and correct!) record.
so, using MooTools, how do i grab the text from the neighbouring sibling when i click the link? hell, even just plain ol' JS will do.
here's the existing function:
function loadRecord(aName) {
console.log("loadRecord called with: "+aName);
user = $('submitterName').value;
id = $('table-id').text; // THIS IS THE PROBLEM RIGHT HERE. >_<
console.log('with user: '+user);
$('recordName').value = aName;
$('addRecordButton').value = 'Update Record';
$('addRecordData').action='_php/updateRecord.php'; // this isn't working either...
var action=$('addRecordData').action;
console.log(action);
checkUserDB(aName,user,id);
}
since there are multiple rows to the table, i can't assign a unique identifier to each ID to any benefit. i'm still stuck trying to pull the table-id's text that relates to the clicked link.
i hope i am clear. any help or illumination would be much appreciated.
TIA crew!
WR!

Here is the solution
HTML
<!--Change your HTML-->
<table>
<tr>
<th>ID</th>
<th>Name</th>
</tr>
<tr>
<td>12</td>
<td><a>Henry</a></td>
</tr>
<tr>
<td>13</td>
<td><a>Julia</a></td>
</tr>
</table>
MooTools
window.addEvent('load', function(){
window.addEvent('click:relay(a)', function(event){//Add your selector inside relay
event.preventDefault();
console.log($(this).getParent('td').getPrevious().get('html'));
//Add Your AJAX code here
});
});
Here you are attaching a click event to anchor then selecting
parent(http://mootools.net/core/docs/1.5.2/Element/Element#Element:getParent)
then as you have ID in previous
element(http://mootools.net/core/docs/1.5.2/Element/Element#Element:getPrevious)
you can grab the previous element and get it's HTML
You can check the pen here http://codepen.io/arifmahmudrana/pen/yYQeJX

Related

How to select specific data in dynamic table using protractor?

I am trying to automate some scenarios using protractor where we need to verify whether the data is updating in dynamic table.
Please find below
HTML Code:
enter image description here
Table in page:
enter image description here
It can be done by verifying that element is present in the DOM with the added Group ID or Group Name.
For Group ID:
element(by.xpath("*//table//tbody//tr//td[1]//p[text()='Amanda Test
Group']")).isDisplayed()
For Group name:
element(by.xpath("*//table//tbody//tr//td[2]//p[text()='Amanda
Group']")).isDisplayed()
I'm assuming you're using Angular2+, yes?
In your HTML Template, you are probably using an *ngFor directive to populate the table dynamically. Add an index to the *ngFor (it's best practices for updating the DOM) in order to add a dynamic id to each element:
<tr *ngFor="let user of user; index as u" id="user-{{u + 1}}">
<td id="userName-{{u + 1}}">
{{user.firstName}} {{user.userName}}<br />
{{user.userName}}
</td>
<td id="userRoles-{{ u + 1 }}">
<span id="role-{{u + 1}}-{{ r + 1 }}" *ngFor="let role of user.roles; index as r">
{{ role.toUpperCase() + ', '}}
</span>
</td>
<!- Omitted code -->
</tr>
In your Page Object:
// Get first user on the table
get firstUser() {
return element(by.id('user-1');
}
// Get a specific user by id
public getUser(index: number) {
return element(by.id(`user-${index}`);
}
// Get all of the attributes for a single user by id
get userAttributes(index: number) {
return element.all(by.id(`user-${index}`);
}
I am not a fan of xpath selectors. Yes, they are faster. But in code that is dynamic or changes frequently, they are the most fragile of selectors. There is no reason your dynamic data cannot have a dynamic ID that clearly identifies each portion of the code you need.
Good luck!

Capybara assert element is empty

Looking for the best way to determine if an element is really empty.
<table id="foo">
<tr>
<td>Cell One</td>
<td></td>
</tr>
</table>
But both of these return true:
find("#foo td:nth-child(1)").should have_content('')
find("#foo td:nth-child(2)").should have_content('')
So I used this:
find("#foo td:nth-child(1)").text.should == 'Cell One'
find("#foo td:nth-child(2)").text.should == ''
Which seems to work, but doesn't check to see if the element may contain other elements. For example it may contain an image, link, or span.
I can check for each one of those individually(image, link, or span), but it seems like there should be better way.
Is there a way to test to see if the element is empty?
You can do the following to check that the element does not have any text and has no child elements (ie is actually empty):
# Has no child elements
find("#foo td:nth-child(2)").all('*').length.should == 0
# Has no text
find("#foo td:nth-child(2)").text.should==''

How to add links in wickets

In java class i need to add list (E.g. list.getFirstName()) to the Label in wicket and that first name shoulb be a hyper link in the html. Below i have code of java and html
the html code
<tr >
<a wicket:id="gotoClass">
<span wicket:id="firstname"></span>
</a>
</tr>
the java class
Iterator<String> brds = list.iterator();
RepeatingView repeating = new RepeatingView("repeating");
add(repeating);
while (brds.hasNext())
{
AbstractItem item = new AbstractItem(repeating.newChildId());
repeating.add(item);
String contact = brds.next();
item.add(new Label("firstname", contact));
}
The above code works for me and i am able to add the label i.e if i have 10 first names in the list i am able to add 10 labels in html.But i try to add the anchor tag in html and
form.add(new BookmarkablePageLink<String>("firstname", gotoClass.class)); in java
then i get the below exception
Last cause: Unable to find component with id 'firstname' in [ [Component id = formname]]
Expected: 'formname.firstname'.
Found with similar names: ''
can anybody help me on this
Regards
Sharath
The link element must be son of the repeating element (as you did firstly). For example:
//...
BookmarkablePageLink<String> link = new BookmarkablePageLink<String>("firstname", gotoClass.class);
item.add(link);
link.add(new Label("firstname", contact));

Typo3 - Custom email newsletters with direct_mail

Im building a newsletter and the start is like this:
DEAR ###USER_gender### ###USER_first_name### ###USER_last_name###
which outpouts
DEAR ###USER_gender### JOHN DOE
and I was hoping it would replace the gender mark with "Miss" and "Sir", depending on the value. How could I do this?
Extra fields have to be added to the field list (see docu). But I'm not sure whether this automatically works with non-string fields. Maybe using a hook is your solution or using another extension which adds a new field to tt_address.
Another solution is to nest marker:
###GENDER_###USER_gender######
and then warp you content in a new template object:
10 = TEMPLATE
10 {
template < yourAlreadyProcessedContent
marks {
GENDER_m = TEXT
GENDER_m.value = Sir
}
}
It's a bit unusual, but sometimes it's very useful.
(Personally I use it to replace version numbers in tt_content records.)
Edit:
Example for Dbugger:
Download the Introduction Package and install it. After that add to the Welcome page a new template record with the following steup:
temp.mainTemplate = TEMPLATE
temp.mainTemplate {
template = TEXT
template.value = (
Foo
###CONTENT###
###CONTENT###
Bar
)
subparts {
CONTENT < styles.content.get
}
}
page = PAGE
page {
typeNum = 0
10 = TEMPLATE
10 {
template < temp.mainTemplate
marks {
TEST = TEXT
TEST.value = ok
}
}
Now include CSS Styled Contnet and enable the following options:
clear constants, clear setup, rootlevel
The output should look like that:
Foo
Congratulations ...
Bar
If you add ###TEST### to the the tt_content record on the welcome page it will be replaced with ok.
This should work with direct mail, too.
Edit:
I'm sorry, this only works which normal extension which are use in the rendering process.
a little bit late, but here's the best solution for the salutation in direct_mail & tt_address .. works perfect for me. The personalized marker is just ###USER_salutation###,
https://blog.webentwickler.at/individuelle-marker-in-direct-mail/

PHP Undefined Index Notice / Error

A page I have in my app will not display the required text so I checked my Apache error log and I found the following notice/error.
PHP Notice: Undefined index: PetManager_Model_Groomprocedures display.phtml on line 34
It is due to the fact that I'm trying to display a result from a query and it can't seem to obtain this item from my result array.
The situation is I'm querying a booking table that is related to a services table (theses elements display fine) the services table is in turn related to a procedures table(this is the element that will not display).
Can someone tell me where I'm going wrong i.e. my Query or my display code and how can I get this to work.
Query Code from my Display Action
if ($input->isValid()) {
$q = Doctrine_Query::create()
->from('PetManager_Model_Kennelbooking k')
->leftJoin('k.PetManager_Model_Kennelservices s')
->leftJoin('s.PetManager_Model_Groomprocedures g')
->leftJoin('k.PetManager_Model_Clients c')
->leftJoin('k.PetManager_Model_Kennels l')
->where('k.kennelbookingID = ?', $input->id);
if('k.groomingIncluded'==1)
{$q->addWhere('s.groomingGiven=g.groomProceduresID');
}
$result = $q->fetchArray();
if (count($result) == 1) {
$this -> view -> booking = $result[0];
The display code from my phtml file
<td class="key">Grooming Procedure </td>
</tr>
<tr>
<?php if($this->booking['PetManager_Model_Kennelservices']['groomingGiven']==NULL)
echo '<td>'.'There is no grooming procedure associated for this booking'.'</td>';
else echo '<td>'.$this->escape($this->booking['PetManager_Model_Groomprocedures']['groomprocedure']).'</td>';
;?>
</tr>
Many thanks in advance,
Graham
As you can see the index PetManager_Model_Groomprocedures is not defined in the booking-variable.
To see which keys are available do the following in your controller to get a debug output.
echo '<pre>';print_r($result[0]);echo '</pre>';exit;
You will see which keys are available in this array. I guess you are not selecting the wanted row explicitly. You will modify your query this way, that you also do select the wanted row.