SharePoint SPFX (No Framework) How to call function from onclick - sharepoint-online

I am not using React or anything like that. I want to add a onclick function to a like this:
<tr onclick="rowclick(id)">
I have a public function:
public rowClick(id): void {
console.log(id);
}
How can I do something like this?

You could add class or attribute to tr so you could bind as
this.domElement.querySelector('tr.MyTR').addEventListener('click', () => { alert('123') });

Related

Get result of function in Laravel and add to another controller

I have this 1st controller.
class ValidatePassController extends Controller
{
protected function doShow(Post $post, Hash $hash)
{
return view('auth.cab.pcab');
}
}
I need to add if view was returned or something like that in the controller below.
class EditController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
public function xuibomja()
{
if (// in past controller view was returned))
{
return ('stassik');
}
return ('not stassik');
}
}
Any ideas? I have tried to set some vars, but it didn't work, so im out of ideas. Btw can't summary controllers to each other, codes needs to be in different controllers.
It's not the best practice to have a controller to call another controller.
what I recommend you to do is to create a class and move the functionality there, and create a facade to map to this class, and set both controllers to use that common functionality

AdonisJs: Using Hashids

Had already someone used Hashids in AdonisJs?
Being more specific, in a Model, to return a property hashid in an object
I'm working on a migration from Laravel to Adonis.
In Laravel, it's possible just with a couple of code lines in each Model, like this:
use Hashids;
class Menu extends Model
{
use \OwenIt\Auditing\Auditable;
protected $appends = ['hashid'];
public function getHashidAttribute()
{
return Hashids::encode($this->attributes['id']);
}
}
I installed this NPM package: https://www.npmjs.com/package/adonis-hashids, and I tried to figure out how to use like the Laravel way
I'd used Computed Properties (https://adonisjs.com/docs/4.1/database-getters-setters#_computed_properties)
class Menu extends Model {
static get computed () {
return ['hashids']
}
getHashids({ id }) {
return Hashids.encode(id)
}
}

NullReferenceException when trying to get text from inputfield

I am new to unity and want to get a value from a input text field. I found this question
Get text from Input field in Unity3D with C#, but when I execute it the same error always appear: NullReferenceExcpetion : Object reference not set to an instance of an object.
It seems like a stupid mistake and I tried everything but can't seem to fix it.
My code:
void Start () {
var input = gameObject.GetComponent<InputField>();
input.onEndEdit.AddListener(SubmitName);
}
private void SubmitName(string arg0)
{
Debug.Log(arg0);
}
I tried putting InputField input; before the start function and erasing var but still no luck.
If anyone can help me with this problem it would be much appreciated.
Pictures of where my scripts are attached at the moment.
Your code is nearly correct, if you have a look at the documentation, you have to call your method with function before calling the method name. It looks to me like you are mixing c# and JS, here is the `js function:
public class Example {
public var mainInputField;
public function Start() {
// Adds a listener to the main input field
// and invokes a method when the value changes.
mainInputField.onValueChange.AddListener(function() {
ValueChangeCheck();
});
}
// Invoked when the value of the text field changes.
public function ValueChangeCheck() {
Debug.Log("Value Changed");
}
}
the c# solution:
public class MenuController : MonoBehaviour {
[SerializeField]
InputField inputText;
// Use this for initialization
void Start () {
inputText.onValueChange.AddListener(delegate {
DebugInput();
});
}
private void DebugInput(){
Debug.Log ("Input: " + inputText);
}
}
My Hierarchie looks like this:
I created a Canvas and inserted an InputField inside it. The script with the code inside is attached to the Canvas and the InputField connected to the [SerializeField] inside the script in the Canvas.
I would recommend you to make your InputField a class variable, so you can access it easier later. Furthermore you should just create a [SerializeField] for your InputField so you can drag it to your script. This might avoid some mistakes too.
Change InputField(TMP) to InputField(Legacy)

ServiceStack Global Request Filter Not Firing

I have a global request filter for authentication as suggested by mythz (ServiceStack dev), in this SO Answer
My filter:
RequestFilters.Add((httpReq, httpResp, requestDto) =>
{
if (!PublicRoutes.Contains(httpReq.PathInfo))
{
new AuthenticateAttribute().Execute(httpReq, httpResp, requestDto);
}
});
The filter does not fire for me when I request ServiceStack Razor pages that inherit dynamic ViewPage
Example /Default.cshtml:
#inherits ViewPage
<!DOCTYPE html>
<html>
<head>
<title>HOME</title>
...
...
ETC
Down the bottom of the answer, in the comments, the question raiser suggests similar behaviour, but does not accurately describe how to reproduce, so I cannot see a solution.
Is there a solution? Did I do something incorrect?
UPDATE
I've discovered I can declare attributes on my page directly:
#using ServiceStack.ServiceInterface
#inherits ViewPage
#{
new AuthenticateAttribute().Execute(Request, Response, this);
}
<!DOCTYPE html>
...
...
ETC
Or I'm sure I could create a class inherit ViewPage and run them in its Init method and use the new class on the Razor pages.
Both of those solutions seem extraneous and not very DRY, though.
I ended up creating my own ViewPage class to achieve this and invoking the filters after the model has been set on the page:
public abstract class FilterViewPage<TModel> : ViewPage<TModel>
where TModel : class
{
public override void SetModel(object o)
{
base.SetModel(o);
this.AppHost.RequestFilters.ForEach(action => action.Invoke(this.Request, this.Response, this.Model));
this.AppHost.ResponseFilters.ForEach(action => action.Invoke(this.Request, this.Response, this.Model));
}
}
I ensure only top-level pages inherit this, rather than applying it to partials so the filters only fire once.
Well, other than simply checking if someone is logged in, much of the roles based stuff is handled for you based on attributes on the request DTO. For what you are doing there are a few options. The first is to have an empty dto that doesn't do anything:
[Route("/")]
[Authenticate]
public class Default { }
public class DefaultService : Service
{
public object Get(Default req)
{
return new object();
}
}
The second is a simple check if a user is logged in the razor page
#{
var session = Cache.SessionAs<AuthUserSession>();
if (!session.IsAuthenticated) throw new HttpException(403, "You are not logged in.");
}

Symfony2, How to secure all controllers in one place using custom function?

I have defined my controller but I would like to secure ALL of them like below :
// In my Controller Class
public function chooseDateAction()
{
if($this->get('MY.roles_features')
->isGranted($this->container->get('request')->get('_route')))
{
// Do something
}
else
{
throw new AccessDeniedException();
}
return array( );
}
I had to design my own 'isGranted' function because roles are dynamic. BTW the function is working properly !
So my question is do I have to repeat the isGranted function in all of my Controllers or I can put it somewhere to reduce the code redundancy.
I know I have to place isGranted in some top level layer of my security, But the question is how and where ?
Try writing a base controller, which will check upon construction, if isGranted method passes, else throws exception. e.g.:
<?php
namespace Acme\DolanBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
class BaseController extends Controller
{
public function __construct()
{
if(!$this->get('MY.roles_features')
->isGranted($this->container->get('request')->get('_route')))
{
throw new AccessDeniedException('Gooby pls');
}
}
}
Then just extend the BaseController in your other controllers.

Resources